XElement.Element error
I get a "Object not set to an...." when I try to do this. The exceptions hits me on the last line.
xml.Add(new XElement("Root", ""));
xml.Element("Root").Add(new XElement("Sites", ""));
xmlContent = xmlContent.E开发者_运维技巧lement("Root").Element("Sites");
Anyone ?
xmlContent
is null
or xmlElement
doesn't contain an element named Root
. That's all I can say from that little code.
The solution:
From:
xml.Add(new XElement("Root", ""));
xml.Element("Root").Add(new XElement("Sites", ""));
xmlContent = xmlContent.Element("Root").Element("Sites");
To:
xml.Add(new XElement("Root", ""));
xml.Element("Root").Add(new XElement("Sites", ""));
xmlContent = xml.Element("Root").Element("Sites");
I just needed to use the correct instance, xml and not xmlContent.
Thanks!
精彩评论