You must Sign In to post a response.
  • Category: XML

    How to combine xml using two xml input ?


    Are you looking for a way to combine xml using two xml input ? then read this thread to know more about it



    Do you know simple way to get the XML output like below from the input ?

    Attached sample input :
    <Order>
    <headerId>1001<header>
    <Cust> ABC </Cust>
    <LineId>1111</lineId>
    </Order>

    <Order>
    <headerId>1001<header>
    <Cust> ABC </Cust>
    <LineId>2222</lineId>
    </Order>
    .......
    The o/p XML needed:

    <Order>
    <headerId>1001<header>
    <Cust> ABC </Cust>
    <LineId>1111</lineid>
    <LineId>2222</lineid>
    </headerId>
    </Order>
    <Order>
    <headerId>2002<header>
    <Cust> XYZ </Cust>
    <LineId>1111</lineid>
    <LineId>2222</lineid>
    </headerId>
    </Order>
  • #740209
    Hi,

    Get the data form the database to a dataset and you can use WriteXml property of the dataset to create the XML file. Please refer below code,

    private void GenerateXML()
    {
    string strCon = ConfigurationManager.ConnectionStrings["CConnectionString"].ToString();\\Get the connection string form database
    SqlConnection conn = new SqlConnection(strCon);
    conn.Open();
    SqlDataAdapter da = null;
    DataSet ds = new DataSet();
    try
    {
    string strSql = "SELECT [Desc], [Title], [Number] FROM [TableName]";
    da = new SqlDataAdapter(strSql, conn);
    da.Fill(ds, "SampleTable");

    ds.WriteXml("C:\\Test.xml");

    }
    catch (Exception ex)
    {
    lblError.Text = "Error!! <br>+" + ex.Message.ToString();
    }
    finally
    {
    ds.Dispose();
    da.Dispose();
    conn.Close();
    conn.Dispose();
    }
    }


    Regards,
    Asheej T K

  • #740247
    I am bit doubtful about your xml structure, where is the end tag for '<headerId>' and '<header>' in your input xml.
    It looks your your xml has some wrong structure and it may not parse successfully if you load it in XMLDocument class.
    Please elaborate, so that we can help you better.

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #740261
    You have various methods to fetch the required Ouptut.But Surely the simple one is to read the xml input into dataset.

    As prasad Observed You need to make sure that your tags should be in proper way...

    dst.readXml(pathof the xml file);

    there you can select the dataset.select(query)...

    or you can use xmldoc.SelectNodes or Xmldoc.SelectSingleNode();...

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI


  • Sign In to post your comments