473,388 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Reading and writing an XML file

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
Nov 12 '05 #1
1 2793
You have to explicitly call Close on the XmlTextReader before trying to
create the XmlTextWriter.

"Marco Rispoli" <ri******@optonline.net> wrote in message
news:fP**********************@news4.srv.hcvlny.cv. net...
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

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
2
by: Jeevan | last post by:
Hi, I have an array of data (which I am getting from a socket connection). I am working on a program which acts on this data but the program is written to work on data from a file (not from an...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
2
by: John Salerno | last post by:
I wrote this code just to experiment with writing to and reading from a file. It seems to work fine when writing, but when reading the file, it only prints the filepath to the screen, not the file...
7
by: utab | last post by:
Hi there, I am trying to read from a file and at the same time change certain fields of the same field, there are 6 fields in this file like 1 2 3 4 5 6...
8
by: smeenehan | last post by:
This is a bit of a peculiar problem. First off, this relates to Python Challenge #12, so if you are attempting those and have yet to finish #12, as there are potential spoilers here. I have five...
5
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
0
by: yogesh_anand | last post by:
Hi I am using sun solaris 5.9 operating system.Sometimes after reading from and while writing to file process size used to get increase.(it can be after 20th times 40 th time) I doesn't happen...
42
by: psbasha | last post by:
Hi, Is it necessary in Python to close the File after reading or writing the data to file?.While refering to Python material ,I saw some where mentioning that no need to close the file.Correct me...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.