In following XML document , I need to append a node
<DASHBOARD>
<ANNOUNCEMENT>
<DISPLAYTEXT>testin one</DISPLAYTEXT>
</ANNOUNCEMENT>
<ADMINLINKS>
<LINK NAME="Google">"http:\\www.google.com"</LINK>
</ADMINLINKS>
<GENLINKS>
<LINK NAME="Clearquest">"http://clearquest.com/cqweb/"</LINK>
<LINK NAME="Google">http://www.google.com</LINK>
</GENLINKS>
</DASHBOARD>
The issue is I need to add a new node named link under adminlinks and genlinks simultaneously. Here is the piece of code
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("DashBoard.xml");
XmlNode NodeGen = xmldoc.SelectSingleNode("DASHBOARD/GENLINKS");
XmlNode NodeAdmin = xmldoc.SelectSingleNode("DASHBOARD/ADMINLINKS");
XmlNode newLink = xmldoc.CreateNode(XmlNodeType.Element, "LINK", null);
XmlAttribute xa = xmldoc.CreateAttribute("NAME");
xa.Value = LinkName;
newLink.InnerText = Link;
newLink.Attributes.Append(xa);
NodeGen.AppendChild(newLink);
NodeAdmin.AppendChild(newLink);
xmldoc.Save("DashBoard.xml");
This is adding the link under adminlinks but not under genlinks.
You're adding the new LINK node to the GENLINKS node, then moving it to ADMINLINKS. Try this instead:
NodeAdmin.AppendChild(newLink.Clone());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With