开发者

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜