VB从C#XML反序列化DataSet

时间:2013-11-08 11:09:03

标签: xml vb.net xmldocument xml-deserialization

以下代码抛出XML反序列化错误(20,2),我不知道为什么。 XmlSerialiser是否有一些特殊的特殊功能可以知道DataSets的反序列化?

Dim strStringReader As StringReader = New StringReader(strValue)
Dim oXS As XmlSerializer = New XmlSerializer(strObjectType)
Deserialize = oXS.Deserialize(strStringReader)

这是xml(在字符串strValue中可用):

<?xml version='1.0' encoding='utf-16'?>
<DataTable>
<xs:schema id='DocumentElement' xmlns='' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
  <xs:element name='DocumentElement' msdata:IsDataSet='true' msdata:UseCurrentLocale='true'>
    <xs:complexType>
      <xs:choice minOccurs='0' maxOccurs='unbounded'>
        <xs:element name='tblCategoryLanguageElements'>
          <xs:complexType>
            <xs:sequence>
              <xs:element name='_LE_LanguageID' type='xs:string' minOccurs='0' />
              <xs:element name='_LE_FieldID' type='xs:string' minOccurs='0' />
              <xs:element name='_LE_Value' type='xs:string' minOccurs='0' />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' xmlns:diffgr='urn:schemas-microsoft-com:xml-diffgram-v1'>
  <DocumentElement>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements1' msdata:rowOrder='0' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>1</_LE_FieldID>
      <_LE_Value>Components</_LE_Value>
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements2' msdata:rowOrder='1' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>2</_LE_FieldID>
      <_LE_Value>Imported by OT2KARTRISSync</_LE_Value>
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements3' msdata:rowOrder='2' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>3</_LE_FieldID>
      <_LE_Value />
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements4' msdata:rowOrder='3' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>4</_LE_FieldID>
      <_LE_Value />
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements5' msdata:rowOrder='4' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>5</_LE_FieldID>
      <_LE_Value />
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements6' msdata:rowOrder='5' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>8</_LE_FieldID>
      <_LE_Value />
    </tblCategoryLanguageElements>
  </DocumentElement>
</diffgr:diffgram>
</DataTable>

职位(20,2)是这样的:

<diffgr:diffgram xmlns:msdata='urn:sche...

任何帮助表示赞赏!!

MadMaxApp

1 个答案:

答案 0 :(得分:2)

对于DataSet和DataTables,有writeread Xml的特殊方法。 DataSet和DataTables可以通过多种方式进行序列化,因此存在一些过载。从您在问题中显示的XML中,我怀疑调用者向您的Web服务发送DiffGram DataTable,这是一种特殊格式,包含对DataSet或DataTable中的数据所做的更改。 /> 您可以使用ReadXml重载之一来阅读DiffGram。