By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

xml writer error

P: n/a

Hello ,
I am trying to write to xml document (c#) by this code:
XmlTextWriter xml_writer=null;
xml_writer=new XmlTextWriter("Database.xml",null);
xml_writer.WriteStartDocument();
xml_writer.WriteStartElement("", "Account", "");
The problem is that when I am trying to open the xml I see there such an
error (instead of the normal xml doc):

XML document must have a top level element. Error processing resource

Someone can tell me what is wrong?
Thank you very much!


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
juli,

You must close the tags that you have opened, in this case the tag Account.
Do that by calling WriteEndElement().
When you are finished writing the document, call WriteEndDocument().
This method automatically closes any tags still open.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"juli jul" <ju******@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...

Hello ,
I am trying to write to xml document (c#) by this code:
XmlTextWriter xml_writer=null;
xml_writer=new XmlTextWriter("Database.xml",null);
xml_writer.WriteStartDocument();
xml_writer.WriteStartElement("", "Account", "");
The problem is that when I am trying to open the xml I see there such an
error (instead of the normal xml doc):

XML document must have a top level element. Error processing resource

Someone can tell me what is wrong?
Thank you very much!


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

P: n/a
Hello,
I tried to do that:
xml_writer.WriteEndElement();
xml_writer.WriteEndDocument();

and still get the error :
XML document must have a top level element. Error processing resource

Thank you very much!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a
And then, of course; finish up calling Close().

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"juli jul" <ju******@yahoo.com> wrote in message
news:ew**************@tk2msftngp13.phx.gbl...
Hello,
I tried to do that:
xml_writer.WriteEndElement();
xml_writer.WriteEndDocument();

and still get the error :
XML document must have a top level element. Error processing resource

Thank you very much!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.