|
-
Jul 12th, 2007, 07:22 AM
#1
Thread Starter
Hyperactive Member
[Resolved] Generate the following XML from C#
Greetings everyone,
I want to generate the following XML thru C#. Can someone please help me here with the code.
<ns0:Ims_Request xmlns:ns0="http://IMSProject.IMS_Request">
<ProductId>10</ProductId>
<ProductName>ProductName_0</ProductName>
<Price>10</Price>
<QtyAvail>10</QtyAvail>
<QtyReq>5</QtyReq>
</ns0:Ims_Request>
I want the C# code to generate a similiar XML with all the tags and namespaces.
Last edited by toughcoder; Jul 14th, 2007 at 05:13 AM.
Reason: issue resolved
If Not VB Then Exit
------------------------------------------------
visit me @ http://mzubair.50g.com/
-
Jul 12th, 2007, 10:53 AM
#2
Re: Generate the following XML from C#
Hi there,
I definitely can't promise that this is the correct way since I'm still learning Xml myself, but you can try something like this.
c# Code:
// Write some Xml.
private void button1_Click(object sender, EventArgs e)
{
XmlTextWriter xw = new XmlTextWriter("c:\\text.xml", null);
xw.WriteStartDocument();
xw.WriteStartElement("ns0:Ims_Request");
xw.WriteAttributeString("xmlns", "ns0", null, "http://IMSProject.IMS_Request");
xw.WriteStartElement("ProductId");
xw.WriteString("10");
xw.WriteEndElement();
xw.WriteStartElement("ProductName");
xw.WriteString("Product_0");
xw.WriteEndElement();
xw.WriteStartElement("Price");
xw.WriteString("10");
xw.WriteEndElement();
xw.WriteStartElement("QtyAvail");
xw.WriteString("10");
xw.WriteEndElement();
xw.WriteStartElement("QtyReq");
xw.WriteString("5");
xw.WriteEndElement();
xw.WriteEndElement();
xw.WriteEndDocument();
xw.Close();
}
Good luck.
-
Jul 13th, 2007, 09:18 PM
#3
Thread Starter
Hyperactive Member
Re: Generate the following XML from C#
Thanks nmadd,
Worked great and gave the exact result. Cheers to u...
If Not VB Then Exit
------------------------------------------------
visit me @ http://mzubair.50g.com/
-
Jul 13th, 2007, 09:23 PM
#4
Re: Resolved: Generate the following XML from C#
Glad it worked for you. Good luck on your project.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|