Public static datatable getdatatable (string xmlstr) <br/>{< br/> xmldocument Doc = new xmldocument (); <br/> Doc. loadxml (xmlstr); </P> <p> xmlnodelist xlist = Doc. selectnodes ("// able/rows"); <br/> datatable dt = new datatable (); <br/> datarow Dr; </P> <p> for (INT I = 0; I <xlist. count; I ++) <br/>{< br/> DR = DT. newrow (); <br/> xmlelement Xe = (xmlelement) xlist. item (I); <br/> for (Int J = 0; j <Xe. Attributes. Count; j ++) <br/>{< br/> If (! DT. columns. contains ("@" + Xe. attributes [J]. name) <br/> DT. columns. add ("@" + Xe. attributes [J]. name); <br/> Dr ["@" + Xe. attributes [J]. name] = Xe. attributes [J]. value; <br/>}< br/> for (Int J = 0; j <Xe. childnodes. count; j ++) <br/>{< br/> If (! DT. columns. contains (Xe. childnodes. item (j ). name) <br/> DT. columns. add (Xe. childnodes. item (j ). name); <br/> Dr [Xe. childnodes. item (j ). name] = Xe. childnodes. item (j ). innertext; <br/>}< br/> DT. rows. add (DR); <br/>}< br/> return DT; <br/>}</P> <p> Public static string getxml (datatable DT) <br/>{< br/> string strxml = @ "<? XML version = '1. 0' encoding = 'utf-8'?> <Datatable/> "; <br/> xmldocument Doc = new xmldocument (); <br/> Doc. loadxml (strxml); <br/> xmlnode root = Doc. selectsinglenode ("// datatable"); <br/> // create a subnode <br/> for (Int J = 0; j <DT. rows. count; j ++) <br/>{< br/> xmlelement Xe = Doc. createelement ("rows"); <br/> xmlelement xechild = NULL; <br/> If (! Object. equals (DT, null) <br/>{< br/> for (INT I = 0; I <DT. columns. count; I ++) <br/>{< br/> If (DT. columns [I]. columnname. startswith ("@") <br/>{< br/> string attributename = DT. columns [I]. columnname. replace ("@", ""); <br/> // set attributes for this subnode <br/> Xe. setattribute (attributename, DT. rows [J] [I]. tostring (); <br/>}< br/> else <br/>{< br/> xechild = Doc. createelement (DT. columns [I]. columnname); </P> <p> try <br/>{< br/> xechild. innerxml = DT. rows [J] [I]. tostring (); <br/>}< br/> catch <br/> {<br/> xechild. innertext = DT. rows [J] [I]. tostring (); <br/>}< br/> Xe. appendchild (xechild); <br/>}< br/> // Save the sub-node Settings <br/> root. appendchild (xe); <br/>}< br/> return Doc. innerxml. tostring (); <br/>}