[Mono-list] Xml reading & writing.

Petit Eric surfzoid at gmail.com
Thu Sep 18 03:32:30 EDT 2008


2008/9/18 Neil Munro <neilmunro at gmail.com>:
>
>
> 2008/9/17 Petit Eric <surfzoid at gmail.com>
>>
>> 2008/9/17 Neil Munro <neilmunro at gmail.com>:
>> >
>> >
>> > 2008/9/17 Jonathan Pryor <jonpryor at vt.edu>
>> >>
>> >> On Wed, 2008-09-17 at 02:43 +0100, Neil Munro wrote:
>> >> > I have an xml file that is my applications preferences, it's an
>> >> > update
>> >> > tool, now this update tool can update from multiple sources. If no
>> >> > preferences file is found on first run, a default set are saved. Now
>> >> > if the user wishes to add a new update source to the xml file I need
>> >> > to place the <UpdateSource>blah</UpdateSource> in the correct part of
>> >> > the file, since the file holds ALL application preferences, I can't
>> >> > just dump a new source at the end of the text file.
>> >> >
>> >> > I guess my question is, what's the best way to solve this problem?
>> >>
>> >> As with many things, there are *several* ways to do this:
>> >>
>> >>  * System.Xml.XmlDocument:
>> >>    http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx
>> >>    Provides a DOM oriented XML manipulation API.
>> >>    Pro: Somewhat easy to use.
>> >>    Con: Loads the entire document into memory, so not very useful for
>> >>         large documents.
>> >
>> > This looks like the solution I am going to go for.
>> >
>> >>
>> >>  * System.Xml.XmlReader & System.Xml.XmlWriter:
>> >>    http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx
>> >>    http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx
>> >>    Pro: Provides a "pull-model" API so that the entire document need
>> >>         not be loaded at once.
>> >>    Con: Not as easy to use as XmlDocument.
>> >>
>> >>  * System.Xml.XPath.IXPathNavigable
>> >>
>> >>
>> >>  http://msdn.microsoft.com/en-us/library/system.xml.xpath.ixpathnavigable.aspx
>> >>    Allows reading/writing of XML-like data w/o requiring XML, but
>> >>    needs an actual implementation that supports reading/writing,
>> >>    which XmlNode (and thus XmlDocument) do.
>> >>
>> >> And I'm probably missing a few...
>> >>
>> >> Unless you're working with a large document (read: several MB and
>> >> larger), I'd suggest either XmlDocument or IXPathNavigable for
>> >> starters.
>> >>
>> >>  - Jon
>> >
>> > 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?
>> Did yu have a look at my class or the MS one ?
>
> The microsoft one, unfortunately my french is not as good as it once was, so
> I have trouble making sense of the file, and I would prefer to use the
> .Net/Mono classes exclusivly if I can get away with it.
For french, time is agaisnt me sorry, but yu can use :
http://babelfish.yahoo.com/
Microsoft one is the snipet i put in previous mail, (configuration) it
should work and be a part of .NET/Mono

>
>>
>> >
>> >
>> > _______________________________________________
>> > Mono-list maillist  -  Mono-list at lists.ximian.com
>> > http://lists.ximian.com/mailman/listinfo/mono-list
>> >
>> >
>>
>>
>>
>> --
>>
>> Cordially.
>>
>> Small Eric Quotations of the days:
>>
>> ---------------------------------------------------------------------------
>> If one day one reproaches you that your work is not a work of
>> professional, say you that:
>> Amateurs built the arch of Noah, and professionals the Titanic.
>>
>> ---------------------------------------------------------------------------
>>
>> Few people are done for independence, it is the privilege of the powerful
>> ones.
>>
>> ---------------------------------------------------------------------------
>>
>> No key was wounded during the drafting of this message.
>
>



-- 

Cordially.

Small Eric Quotations of the days:
---------------------------------------------------------------------------
If one day one reproaches you that your work is not a work of
professional, say you that:
Amateurs built the arch of Noah, and professionals the Titanic.
---------------------------------------------------------------------------

Few people are done for independence, it is the privilege of the powerful ones.
---------------------------------------------------------------------------

No key was wounded during the drafting of this message.


More information about the Mono-list mailing list