[Mono-list] Xml reading & writing.
Jonathan Pryor
jonpryor at vt.edu
Thu Sep 18 09:54:43 EDT 2008
On Wed, 2008-09-17 at 22:36 +0100, Neil Munro wrote:
> So I have this:
>
> // Save it in the prefs.xml file.
> XmlDocument xmlDoc = new XmlDocument( );
>
> xmlDoc.Load( sPath_To_Prefs_File );
>
> Now I know that the whole document is loaded into memory at this
> point, how would i traverse the document in memory to get to the
> <UpdateSource> section, read until there are no more of that tag and
> add a new update source after the last one and before the next line?
Read the documentation I pointed you to. :-)
To see if the UpdateSource element is present, you could learn XPath and
do:
XmlNode updateSource =
xmlDoc.SelectSingleNode("/path/to/UpdateSource");
if (updateSource == null) {
// add updateSource
XmlNode parent = xmlDoc.SelectSingleNode("/path/to");
updateSource = xmlDoc.CreateElement ("UpdateSource");
// fill updateSource with nested elements, attributes, etc.
parent.AppendChild (updateSource);
}
The above likely won't be perfect, but should be enough to get you
started...
Again, read the documentation. It's full of examples.
- Jon
More information about the Mono-list
mailing list