473,388 Members | 1,277 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.

Error in xml file after write

I read and write from an xml file. Running the code below removes the first
part of the xml declaration. That is, instead of "<?xml...>" I get "ml...>"
in the begin of the xml file. The code is part of a service. I hope someone
can help.

Regards
Martin

XmlDocument scanDoc = new XmlDocument();
scanDoc.Load(@"scan.xml");

XmlNode newElem = scanDoc.CreateNode(XmlNodeType.Element, "tag", null);
newElem.InnerXml = "<tag1></tag1>" + "<tag2></tag2+
... +"<tagX></tagX>";

newElem["tag1"].InnerText = argTag1;
XmlElement valueElem = scanDoc.CreateElement("tag1");
....
newElem["tagX"].InnerText = argTagX;
XmlElement commentElem = scanDoc.CreateElement("tagX");

scanDoc.DocumentElement.PrependChild(newElem);

scanDoc.PreserveWhitespace = true;
XmlTextWriter xmlWrtr = new XmlTextWriter(@"scan.xml", Encoding.ASCII);
xmlWrtr.Formatting = Formatting.Indented;
xmlWrtr.Indentation = 2;
scanDoc.Normalize();
scanDoc.WriteTo(xmlWrtr);
xmlWrtr.Close();

Jul 8 '06 #1
1 1091
Write to another file instead of the same file and see.

chanmm

"Martin" <Ma****@discussions.microsoft.comwrote in message
news:57**********************************@microsof t.com...
>I read and write from an xml file. Running the code below removes the first
part of the xml declaration. That is, instead of "<?xml...>" I get
"ml...>"
in the begin of the xml file. The code is part of a service. I hope
someone
can help.

Regards
Martin

XmlDocument scanDoc = new XmlDocument();
scanDoc.Load(@"scan.xml");

XmlNode newElem = scanDoc.CreateNode(XmlNodeType.Element, "tag", null);
newElem.InnerXml = "<tag1></tag1>" + "<tag2></tag2+
... +"<tagX></tagX>";

newElem["tag1"].InnerText = argTag1;
XmlElement valueElem = scanDoc.CreateElement("tag1");
...
newElem["tagX"].InnerText = argTagX;
XmlElement commentElem = scanDoc.CreateElement("tagX");

scanDoc.DocumentElement.PrependChild(newElem);

scanDoc.PreserveWhitespace = true;
XmlTextWriter xmlWrtr = new XmlTextWriter(@"scan.xml", Encoding.ASCII);
xmlWrtr.Formatting = Formatting.Indented;
xmlWrtr.Indentation = 2;
scanDoc.Normalize();
scanDoc.WriteTo(xmlWrtr);
xmlWrtr.Close();

Jul 9 '06 #2

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

Similar topics

4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
2
by: SayMyName | last post by:
Due to my browser being danishm the error message will not mean much t most of you. It is an "Unspecified problem" with "Provide (0x80004005)" POST Data: error '80020009' The error only arrives...
6
by: Tim Cowan | last post by:
Hi I have the following code to write an error file and it is supposed to open the HTML file in a browser when an error occurs. It creates the file Ok but doesn't open the new browser and doesn't...
13
by: Jerry C | last post by:
I am using some sample code from gotdotnet to Create DataSet mappings from a xsd schema. I am geting this error. code and error below. I might mention there is also a publictypelibrary file with...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
0
by: UJ | last post by:
I am trying to write a routine to upload a file through a web service to our server. I've enclosed the following code and when I run it I get an error: Exception Occurred. Error: Logon failure:...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
1
by: Alexander Higgins | last post by:
>>Thanks for the response.... Point Taken but this is not the case. Thus, if a person writes a text file on her or his computer and does not use UNICODE to save it, the current code page is...
0
by: poojamangal | last post by:
I want to upload images or pdf files. but i m unable to do so. i got error. please help me to sort it out.. my code is: <% 'on error resume next Class FreeASPUpload Public UploadedFiles...
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.