Here is how it will work :
XmlDocument xmlDoc = new XmlDocument()
xmlDoc.Load(@"C:\Well.xml")
XmlNode node = xmlDoc.SelectSingleNode("/gpx/waypoints/waypoint[@a='2']/name")
node.InnerText = "Something"
xmlDoc.Save(@"C:\Well.xml")
Hope it helped! :)
Update 1:
From the subject of your question, it seems that you don't want to load the whole XML.
Well there is a class
XmlTextWriter
which is a stream-based loading of XML and it won't load the whole XML. It will read node by node, in contrast to
XmlDocument
which is a in-memory based loading of XML, it loads the whole XML into memory.
Now coming back to the point, after searching for more info on the internet, it was just like I thought,
XmlTextWriter
cannot modify the Xml nodes. So your solution will be to use the
XmlDocument
itself for Modifying the nodes.
I did however tried in this way :
XmlTextReader reader = new XmlTextReader(path);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "waypoint")
{
if (reader.GetAttribute("a") == "2")
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(reader.ReadOuterXml());
XmlNode node = xmlDoc.SelectSingleNode(".");
node.InnerText = "Something";
}
}
}
:(
So it didn't work for me.
I will still try to figure out a solution for this.
Update 2:
Found some articles in CodeProject. According your requirements, check these :
-First you can split your large xml file into smaller ones. Check this article :
http://www.codeproject.com/KB/XML/SplitLargeXMLintoSmallFil.aspx#xx2994884xx[
^]
- After finding the node, load the smaller XML into an XmlDocument and then edit like I did in my solution. Then merge the xml files like mentioned in this article :
http://www.codeproject.com/KB/XML/XStreamingElement_Merge.aspx[
^]
Try it out. Good luck!