Reading and updating xml c
Or should I load the file to XElement every time the application performs a CRUD operation?
P/s : even if I have to re-load the file to XElement every time calling the CRUD functions, I still have to save the file immediately after very changes the application has made to the file (now is a XElement object), because I don't want to lost any data lost due to power failure or unhandled exception ...
The XML is basically parsed into an Xml Node which is the root element and then you can access the child elements using the Child Nodes property.
However, the Xml Node class gives you access to a lot of other information as well, for instance the name of the tag, the attributes, the inner text and the XML itself.
You can use XPath where that's appropriate, or the built-in axis methods ( For the task in hand - (read existing doc, write, and modify in a formalised way) I'd go with XPath Document run through an Xsl Compiled Transform.In the previous chapter, we used the Xml Document class to parse an XML file. A new class was introduced in the example, which is very essential to parsing XML with Xml Document: The Xml Node class. To add then delete a song, just use the following Xml Document doc = new Xml Document(); Xml Element ea = doc. Select Nodes(@"/Song"); // Create the new nodes using doc Xml Node new Song = doc. Append Child(new Song); Note that the above statement is oviously not for your xml, but to prove a point about // Using // removes the need for your doc Sub document and Songs Node element.