Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 at 14:14
add comment

3 Answers

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: http://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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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