1
Answer

[ANSWERED] Amend XML

Jay Webster

Jay Webster

13y
2.1k
1
Hi,

I have the following XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>
<MAP>
<TILES>
<TILE ID="1">
<START>FALSE</START>
<EXIT>FALSE</EXIT>
</TILE>
<TILE ID="2">
<START>FALSE</START>
<EXIT>FALSE</EXIT>
</TILE>
<TILE ID="3">
<START>FALSE</START>
<EXIT>FALSE</EXIT>
</TILE>
</TILES>
</MAP>

If I want to say search for a tile node with id attribute of 3 and change the START node to TRUE.

I have got this so far:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("xmlfile.xml");
XmlNode node = xmlDoc.SelectSingleNode("/MAP/TILES/TILE/START");
node.Attributes[0].Value = "TRUE";
xmlDoc.Save("xmlfile.xml");

But I have no idea how to find and change only the node with ID = 3.

Thanks

Jay
Answers (1)