简体   繁体   English

在xml行为中添加节点

[英]Adding node in xml behavior

This is my code: 这是我的代码:

XmlElement tagToAdd = xmlDoc.CreateElement("oneTag");
tagToAdd.InnerText = "blah";
addMyNodes.Add(tagToAdd);
xmlDoc1.Root.Element("Properties").Add(addMyNodes);
xmlDoc1.Save(@"C:\Users\John\Desktop\Ugh.xml");

On the line "addMyNodes.Add(tagToAdd);" 在“ addMyNodes.Add(tagToAdd);”行上 I want the tagToAdd to be added to addMyNodes which is XElement. 我希望将tagToAdd添加到XElement的addMyNodes中。 But, it doesn't add it. 但是,它没有添加。

xmlDoc1 and xmlDoc are loaded on the same file, but one is XmlDocument and one is XDocument. xmlDoc1和xmlDoc加载在同一文件上,但一个是XmlDocument,一个是XDocument。

You can't really mix XmlDocument/XmlElement and XDocument/XElement. 您不能真正混合使用XmlDocument / XmlElement和XDocument / XElement。

Use XDocument/XElement for everything if you can. 如果可以,请对所有内容使用XDocument / XElement。 XmlDocument/XmlElement is more or less deprecated. XmlDocument / XmlElement或多或少不推荐使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM