Results 1 to 4 of 4

Thread: [Resolved] Generate the following XML from C#

  1. #1
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 02
    Location
    Near, Very Near
    Posts
    340

    Resolved [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/

  2. #2
    Frenzied Member nmadd's Avatar
    Join Date
    Jun 07
    Location
    Colorado, U.S.A.
    Posts
    1,676

    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:
    1. // Write some Xml.
    2.         private void button1_Click(object sender, EventArgs e)
    3.         {
    4.             XmlTextWriter xw = new XmlTextWriter("c:\\text.xml", null);
    5.  
    6.             xw.WriteStartDocument();
    7.             xw.WriteStartElement("ns0:Ims_Request");
    8.             xw.WriteAttributeString("xmlns", "ns0", null, "http://IMSProject.IMS_Request");
    9.            
    10.             xw.WriteStartElement("ProductId");
    11.             xw.WriteString("10");
    12.             xw.WriteEndElement();
    13.  
    14.             xw.WriteStartElement("ProductName");
    15.             xw.WriteString("Product_0");
    16.             xw.WriteEndElement();
    17.  
    18.             xw.WriteStartElement("Price");
    19.             xw.WriteString("10");
    20.             xw.WriteEndElement();
    21.  
    22.             xw.WriteStartElement("QtyAvail");
    23.             xw.WriteString("10");
    24.             xw.WriteEndElement();
    25.  
    26.             xw.WriteStartElement("QtyReq");
    27.             xw.WriteString("5");
    28.             xw.WriteEndElement();
    29.  
    30.             xw.WriteEndElement();
    31.             xw.WriteEndDocument();
    32.             xw.Close();
    33.         }

    Good luck.

  3. #3
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 02
    Location
    Near, Very Near
    Posts
    340

    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/

  4. #4
    Frenzied Member nmadd's Avatar
    Join Date
    Jun 07
    Location
    Colorado, U.S.A.
    Posts
    1,676

    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
  •