This operation would create an incorrectly structured document. XDocument

0

I'm trying to create an XML, but I can not. I want it to have this format:

<item>
      <linktext></linktext>
      <etc..></etc...>
</item>

I can add an item, but when I go through the loop again, it goes out of try and gives me the title error. What am I doing wrong? Here's how I create XML:

XDocument xmlOut = new XDocument();
 XElement item = new XElement("item",
                        new XElement("linktext", processedXML),
                        new XElement("link", "http://www.boe.es/diario_boe/txt.php?id=" + tmpName[1]),
                        new XElement("guid", newPdf.ToString()),
                        new XElement("pubDate", DateTime.Now)
                        );

                    xmlOut.Add(item);
    
asked by anonymous 21.03.2017 / 14:21

1 answer

0

The problem was that I was trying to add multiple elements to the XML root, which is wrong (from what I noticed after some research). What I did was create a XElement <itens> and then instead of:

xmlOut.Add(item);

I used

xmlOut.Root.Element("itens").Add(item);

and the problem has been solved, having several <item> within <itens> , as desired.

    
23.03.2017 / 12:45