Keith,
There are a number of ways to accomplish this. The easiest way, if the XML
document is not huge is the the XmlDocument object to load the XML into it,
find the location where you want to insert elements (either by parsing the
ChildNodes tree or by using SelectSingleNode()) and then simply inserting a
new XML Node with the data you need. This is pretty easy to do.
If the file is large (depends on your environment really - so test) you may
have to use an XmlReader and XmlWriter to read the content of the old XMl
doducment and then re-write the document as you go, adding the new content
as needed.
XmlDom is pretty simple to do - you should be able to find a sample online
easily. XmlReader/Writer is a little more non-obvious <g> and definitely
more work.
As for good books entry level books on XML I like Dan Wahlin's Xml for
ASP.NET developers which hits all the highlights in a very readable and
smallish book.
http://www.amazon.com/exec/obidos/ASIN/0672320398/westwindtechn-20/002-94615
63-3270443
Dino Esposito has another one that's more complete and goes a little deeper
as well as dealing more with data centric issues:
http://www.amazon.com/exec/obidos/ASIN/0735618011/westwindtechn-20/002-94615
63-3270443
I have and use both frequently...
+++ Rick ---
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog
http://www.west-wind.com/wwthreads
----------------------------------
Making waves on the Web
> -----Original Message-----
> From: padnug@xxxxxxxxxxxxxxx [mailto:padnug@xxxxxxxxxxxxxxx]
> On Behalf Of Keith R. Pinster
> Sent: Tuesday, August 02, 2005 10:44 AM
> To: padnug@xxxxxxxxxxxxxxx
> Subject: [padnug] Writing XML data to a file
>
> I was wondering if anyone can point me to an article or book
> that tells me how to write individual XML nodes into the
> middle of a file.
>
> Here's what I've got: I've got an XML file with several
> "tables" that are used to configure a web page. I want to
> take 1 of these "tables", modify the data and then write it
> back out to the file. The XML file may be modified (sections
> added or deleted) and my little config app is being written
> for only 1 specific section. I'm trying to avoid reading the
> entire XML file in and then writing it to file from scratch.
>
> Is there a way to do this?
>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor
> --------------------~--> <font face=arial size=-1><a
> href="http://us.ard.yahoo.com/SIG=12heu5cgu/M=362131.6882499.7
> 825260.1510227/D=groups/S=1705007709:TM/Y=YAHOO/EXP=1123011906
> /A=2889191/R=0/SIG=10r90krvo/*http://www.thebeehive.org
> ">Get Bzzzy! (real tools to help you find a job) Welcome to
> the Sweet Life - brought to you by One Economy</a>.</font>
> --------------------------------------------------------------
> ------~->
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
<font face=arial size=-1><a
href="http://us.ard.yahoo.com/SIG=12hr7cah0/M=362131.6882499.7825260.1510227/D=groups/S=1705007709:TM/Y=YAHOO/EXP=1123013919/A=2889191/R=0/SIG=10r90krvo/*http://www.thebeehive.org
">Get Bzzzy! (real tools to help you find a job) Welcome to the Sweet Life
- brought to you by One Economy</a>.</font>
--------------------------------------------------------------------~->
|