4

I am doing metadata update for Pages as below. I am constantly getting the below error

XML validation error. Reason: The required attribute 'http://www.w3.org/1999/xlink:href' is missing..

Code is below.

XElement xMetadata = XElement.Parse(pageData.Metadata);
XNamespace xnsp = "Tridion.Schema.Metadata.PageMetadata";
XNamespace ns3 = XNamespace.Get("http://www.w3.org/1999/xlink");

XElement addNode= new XElement(xnsp + "add", new XAttribute(XNamespace.Xmlns + "xlink", ns3));

                foreach (var value in xxxx)
                {

                    XElement map= new XElement(xnsp+"Map");
                    //Hard coded - TO DO
                    XElement isEnabled = new XElement(xnsp+"IsEnabled","No");
                    XElement path= new XElement(xnsp+"Path", value.Path);

                    map.Add(isEnabled);
                    map.Add(path);
                    routeRoot.Add(map);
                }
                xMetadata.Add(addNode);                                    

                pageData.Metadata = xMetadata.ToString();

                client.Update(pageData, new ReadOptions());

One more point, metadata already consists of links to one or two configuration components. I tried adding xlink namespace to metadata root node but it dint solve the problem. Added its namespace to solve the issue but it dint help.

Let me also know if there is a better way to achieve this.

  • It would be great, if you can share your actual metadata XML. Since your code doesn't look like proper implementation. – Siva Charan Feb 24 '14 at 14:14
4

According to "http://www.w3.org/1999/xlink" namespace you are supposed to have href attribute, which you are not adding. You should get XML similar to this: https://stackoverflow.com/questions/12778958/how-to-set-the-multimedia-link-field-using-core-service

The best way to solve your porblem is to create link manually (through UI) and then make sure you recreating the same with the code.

| improve this answer | |
1

First manually make a working page with your metadata. Then compare that to what you're making via code (hint: use the debugger or logger to inspect). This should tell you what exactly isn't right so that you can move forward.

| improve this answer | |
1

It looks like you are constructing the XAttribute incorrectly when you say:

new XAttribute(XNamespace.Xmlns + "xlink", ns3)

Firstly, it's more idiomatic in XLinq to use the overloaded assignment operator to create an XNamespace

XNamespace xlink = "http://www.w3.org/1999/xlink";

then you can use it (also by way of an operator overload) like this:

new XAttribute(xlink + "href", yourHrefValue)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.