Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit Xml Node

Tags:

c#

xml

I have an xml document where an xml node with a particular name, say 'Data' can appear anywhere in the xml document i.e anywhere in the hierarchy. I need to read these nodes with their node name alone and edit the node attributes. What is the easiest way to do it?

like image 697
softwarematter Avatar asked Apr 16 '26 13:04

softwarematter


1 Answers

XmlDocument doc = new XmlDocument();
doc.Load(@"Test.xml");
XmlNodeList elem = doc.GetElementsByTagName("Data");
foreach (XmlNode tag in elem)
{
 //do whatever you want to the attribute using SetAttribute method
}

XmlElement.GetElementsByTagName Method would do the trick

like image 111
TStamper Avatar answered Apr 19 '26 03:04

TStamper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!