Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : Reading and writing an XML file


Chris Lovett
6/30/2004 10:00:32 PM
You have to explicitly call Close on the XmlTextReader before trying to
create the XmlTextWriter.

[quoted text, click to view]

Marco Rispoli
6/30/2004 10:06:03 PM
Hello folks!

I have to read an XML file, add some elements and write it back.

I seem to have no problem doing the first 2 things but then I get

The process cannot access the file "c:/file.xml" because it is being used by
another process.

... when I try to do the third thing: saving.

This is how I am doing it:

XmlDocument oXml=new XmlDocument();
oXml.Load(new XmlTextReader(@"c:\file.xml"));

// do the element work here

oXml.Save(new XmlTextWriter(@"c:\file.xml", System.Text.Encoding.ASCII));

The error occurs right at the Save call.

Any of you more experienced folks ever tried to do anything like this?

Thanks!

--
Marco Rispoli - NJ, USA / PP-ASEL
My on-line aviation community -> http://www.thepilotlounge.com

AddThis Social Bookmark Button