What is the C# code for XML file by using XmlWriter Class [Resolved]

Posted by Kamalakanta.Nayak09 under C# on 7/13/2012 | Points: 10 | Views : 987 | Status : [Member] | Replies : 2
<SellingStatus>
<ConvertedCurrentPrice currencyID="USD">153.68</ConvertedCurrentPrice>
<CurrentPrice currencyID="GBP">99.0</CurrentPrice>

</SellingStatus>

What is the C# for above xml by using the XmlWriter Class?
I want code specially for <ConvertedCurrentPrice currencyID="USD">153.68</ConvertedCurrentPrice>
It is urgent for me.

Thanks,
K.K



Responses

Posted by: Premalatha on: 7/13/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
using System;
using System.Text;
using System.Xml;

namespace WritingXml
{
class Program
{
static void Main(string[] args)
{
XmlWriter xmlWriter = XmlWriter.Create("test.xml");

xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("users");

xmlWriter.WriteStartElement("user");
xmlWriter.WriteAttributeString("age", "42");
xmlWriter.WriteString("John Doe");
xmlWriter.WriteEndElement();

xmlWriter.WriteStartElement("user");
xmlWriter.WriteAttributeString("age", "39");
xmlWriter.WriteString("Jane Doe");

xmlWriter.WriteEndDocument();
xmlWriter.Close();
}
}
}
The above code will create the following XML:
<users>
<user age="42">John Doe</user>
<user age="39">Jane Doe</user>
</users>

Premalatha
Software Engineer

Kamalakanta.Nayak09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/13/2012 [Member] Starter | Points: 25

Up
0
Down
http://www.dotnetperls.com/xmlwriter

Premalatha
Software Engineer

Kamalakanta.Nayak09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response