Editing XML file

  • Thread starter Thread starter Royce Fickling
  • Start date Start date
R

Royce Fickling

I want to manage, i.e., insert, edit, and retrieve data in
a simple XML file. Here is a sample of the file:

<?xml version="1.0" encoding="utf-8"?>
<Backup>
<Settings Compress="true" RunMinimized="true" />
<InPaths>
<InPath>D:\Proj.net</InPath>
</InPaths>
</Backup>

I can write the file with XmlTextWriter, but how do I edit
a given item, say the InPaths collection, after the file
exists. XmlTextWriter seems limited.

TIA,
Royce
 
Royce,
Correct XmlTextWriter is for writing xml files.

While XmlTextReader is for reading xml files.

You could use XmlTextReader to read your file, modify it, and then use
XmlTextWriter to write the file. However! I normally use XmlDocument to load
your document, then use methods on XmlDocument to modify it, then have
XmlDocument write the document. NOTE: XmlDocument can use XmlTextReader &
XmlTextWriter to read & write the document, or you can give it the file
names to read & write from.

Hope this helps
Jay
 
Back
Top