[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.
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.
Re: Generate the following XML from C#
Thanks nmadd,
Worked great and gave the exact result. Cheers to u...
Re: Resolved: Generate the following XML from C#
Glad it worked for you. Good luck on your project. :)