现在在做一个东西。。我需要将数据传给对方,我从数据库里面取得数据库。。怎样子变成xml格式
传送给对方呢对方传给我的也是xml格式的。。怎样子转化成dataset呢
能不能给出示例代码看看呢。。谢谢

解决方案 »

  1.   

    DataSet dataset = new DataSet();
    dataset.ReadXml(filepath);(由XML变成DATASET)
    dataset.WriteXml(filepath);(由DATASET变成XML)
      

  2.   

    忘记说清楚了。。是需要通过序列化为soap的格式的。。怎么做呢
      

  3.   

    - <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    - <SOAP-ENV:Body>
    - <a1:DataSet id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/System.Data/System.Data%2C%20Version%3D1.0.5000.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Db77a5c561934e089">
      <XmlSchema id="ref-3"><?xml version="1.0" encoding="utf-16"?> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="zh-CN"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="Table"> <xs:complexType> <xs:sequence> <xs:element name="AutoID" type="xs:int" msdata:targetNamespace="" minOccurs="0" /> <xs:element name="SpNO" type="xs:string" msdata:targetNamespace="" minOccurs="0" /> <xs:element name="DstAddr" type="xs:string" msdata:targetNamespace="" minOccurs="0" /> <xs:element name="Content" type="xs:string" msdata:targetNamespace="" minOccurs="0" /> <xs:element name="Status" type="xs:string" msdata:targetNamespace="" minOccurs="0" /> <xs:element name="Flag" type="xs:boolean" msdata:targetNamespace="" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema></XmlSchema> 
      <XmlDiffGram id="ref-4"><diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><NewDataSet><Table diffgr:id="Table1" msdata:rowOrder="0"><AutoID>1</AutoID><SpNO>0173678</SpNO><DstAddr>13599226454</DstAddr><Content>晋江政务网测试</Content><Status>DELIVER</Status><Flag>false</Flag></Table><Table diffgr:id="Table2" msdata:rowOrder="1"><AutoID>2</AutoID><SpNO>8173678</SpNO><DstAddr>13194065032</DstAddr><Content> 晋江政务网测试联通</Content><Status>0</Status><Flag>false</Flag></Table></NewDataSet></diffgr:diffgram></XmlDiffGram> 
      </a1:DataSet>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
    我试了一下。但是生成了一些没用的代码,怎么处理呢<a1:DataSet>
    </a1:DataSet>
    这部分中的数据有些乱
      

  4.   

    DataSet ds = new DataSet();   //.....DataAdapter.Fill(ds , "Customers");
           System.Text.StringBuilder sb = new System.Text.StringBuilder();
       System.IO.StringWriter writer = new System.IO.StringWriter(sb);
       ds.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema );
       
       writer.Close();
          string sXmlData = sb.ToString();   System.IO.StringReader reader = new System.IO.StringReader(sXmlData);
       DataSet ds2 = new DataSet();
       ds2.ReadXml(reader);
       Console.WriteLine("TableName : {0}, Record Count : {1}", ds2.Tables[0].TableName, ds2.Tables[0].Rows.Count);