Welcome to Dream.In.Code
Become an Expert!

Join 150,217 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,142 people online right now. Registration is fast and FREE... Join Now!




wrte to xml docoment

 
Reply to this topicStart new topic

wrte to xml docoment

anuruddha
13 Nov, 2007 - 07:13 PM
Post #1

New D.I.C Head
*

Joined: 22 Oct, 2007
Posts: 18


My Contributions
i want to write an xml document by my web application
for eg:- i want to write into xml
<name>anu</name>
this is have to write by string that means...

CODE

string xx = "<name>amr</name>";
XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml", null);
textWriter.WriteStartDocument();
textWriter.WriteStartElement("anuruddha", "");
textWriter.WriteString(xx);
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
close writer
textWriter.Close();


but in my xml document
it is like follwing
<anuruddha>&lt;name&gt;amr&lt;/name&gt;</anuruddha>

what i want is
<anuruddha><name>amr</name></anuruddha>


what i can do
pls help me..

Please use code blocks when posting your code smile.gif => code.gif

This post has been edited by PsychoCoder: 13 Nov, 2007 - 08:41 PM
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Wrte To Xml Docoment
13 Nov, 2007 - 08:30 PM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,285



Thanked: 136 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
You're using an XmlWriter and also hand coding XML. Choose one or the other, not both.

Try this:

CODE

XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml", null);
textWriter.WriteStartDocument();
textWriter.WriteStartElement("anuruddha");
textWriter.WriteStartElement("name");
textWriter.WriteString("amr");
textWriter.WriteEndElement();
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
textWriter.Close();


Or, simpler syntax for elements that just contain a string value.

CODE

XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml", null);
textWriter.WriteStartDocument();
textWriter.WriteStartElement("anuruddha");
textWriter.WriteElementString("name", "amr");
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
textWriter.Close();



Hope this helps.

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:31AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month