1. Write XML from datatable
Private void button#click (Object sender, system. eventargs E)
{
Datatable dttccl0001 = querytccl0001 ();
String strfile = "D: \ tccl0001.xml ";
Xmltextwriter objxml = new xmltextwriter (strfile, encoding. utf8 );
Objxml. writestartdocument ();
Objxml. writestartelement ("inventoryxml ");
Objxml. writeelementstring ("transferid", "123 ");
For (INT I = 0; I <dttccl0001.rows. Count; I ++)
{
Objxml. writestartelement ("inventory ");
Objxml. writeelementstring ("warehouseno", dttccl0001.rows [I] ["warehouseno"]. tostring ());
Objxml. writeelementstring ("customercode", dttccl0001.rows [I] ["customercode"]. tostring ());
Objxml. writeelementstring ("customerpartno", dttccl0001.rows [I] ["customerpartno"]. tostring ());
Objxml. writeelementstring ("customerpartnoversion", dttccl0001.rows [I] ["customerpartnoversion"]. tostring ());
Objxml. writeelementstring ("vendorcode", dttccl0001.rows [I] ["vendorcode"]. tostring ());
Objxml. writeelementstring ("vendorname", dttccl0001.rows [I] ["vendorname"]. tostring ());
Objxml. writeelementstring ("vendorpartno", dttccl0001.rows [I] ["vendorpartno"]. tostring ());
Objxml. writeelementstring ("vendorpartnoversion", dttccl0001.rows [I] ["vendorpartnoversion"]. tostring ());
Objxml. writeelementstring ("mfgcode", dttccl0001.rows [I] ["mfgcode"]. tostring ());
Objxml. writeelementstring ("inventoryqty", dttccl0001.rows [I] ["inventoryqty"]. tostring ());
Objxml. writeelementstring ("partstatus", dttccl0001.rows [I] ["partstatus"]. tostring ());
Objxml. writeelementstring ("onwayqty", dttccl0001.rows [I] ["onwayqty"]. tostring ());
Objxml. writeelementstring ("UOM", dttccl0001.rows [I] ["UOM"]. tostring ());
Objxml. writeelementstring ("Description", dttccl0001.rows [I] ["Description"]. tostring ());
Objxml. writeelementstring ("ref1", dttccl0001.rows [I] ["ref1"]. tostring ());
Objxml. writeelementstring ("ref2", dttccl0001.rows [I] ["ref2"]. tostring ());
Objxml. writeelementstring ("ref3", dttccl0001.rows [I] ["ref3"]. tostring ());
Objxml. writeelementstring ("ref4", dttccl0001.rows [I] ["ref4"]. tostring ());
Objxml. writeendelement ();
}
Objxml. writeendelement ();
Objxml. writeenddocument ();
Objxml. Flush ();
Objxml. Close ();
Txtmessage2.text = "converted successfully ";
}
2. return data from XML to able
Private void button#click (Object sender, system. eventargs E)
{
Xmltextreader XTR = new xmltextreader (@ "D: \ tccl0001.xml ");
While (XTR. Read ())
{
If (XTR. nodetype = xmlnodetype. element)
{
Switch (XTR. localname)
{
Case "transferid ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "warehouseno ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "customercode ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "customerpartno ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "customerpartnoversion ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "vendorcode ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "vendorname ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "vendorpartno ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "vendorpartnoversion ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "mfgcode ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "inventoryqty ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "partstatus ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "onwayqty ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "UOM ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "Description ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "ref1 ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "ref2 ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "ref3 ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
Case "ref4 ":
Httpcontext. Current. response. Write (XTR. readstring () + "<br> ");
Break;
}
}
}
}