简体   繁体   中英

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);" I want the tagToAdd to be added to addMyNodes which is XElement. But, it doesn't add it.

xmlDoc1 and xmlDoc are loaded on the same file, but one is XmlDocument and one is XDocument.

You can't really mix XmlDocument/XmlElement and XDocument/XElement.

Use XDocument/XElement for everything if you can. XmlDocument/XmlElement is more or less deprecated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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