我试图在一个简单的程序中使用以下代码对XML进行反序列化,但收到错误。
System.InvalidOperationException:'XML文档(2,2)中存在错误。' InvalidOperationException:意外。
Const FILENAME As String = "C:\Users\rob\Downloads\TCP Integration Latest\SalesFiles\gpos156\g0001001.180"
Dim ds As New DataSet
Dim xmlSerializer As XmlSerializer = New XmlSerializer(ds.GetType)
Dim readStream As FileStream = New FileStream(FILENAME, FileMode.Open)
ds = CType(xmlSerializer.Deserialize(readStream), DataSet)
readStream.Close()
DataGridView1.DataSource = ds.Tables(0)
我的XML非常大,但是从..开始看起来像这样。如果需要,我可以上传整个文档。
任何朝着正确方向的建议都是很好的。
<?xml version="1.0" standalone="yes"?>
<GPoSData>
<xs:schema id="GPoSData" xmlns="gposdata" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="GPoSData" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="DT180">
<xs:complexType>
<xs:sequence>
<xs:element name="TranCode" type="xs:long" minOccurs="0" />
<xs:element name="ClerkCode" type="xs:int" minOccurs="0" />
<xs:element name="SalesPersonCode" type="xs:int" minOccurs="0" />
<xs:element name="PersonCount" type="xs:short" minOccurs="0" />
<xs:element name="TableCode" type="xs:int" minOccurs="0" />
<xs:element name="CustomerCode" type="xs:int" minOccurs="0" />
<xs:element name="BillCode" type="xs:long" minOccurs="0" />
<xs:element name="SaleTotal" type="xs:decimal" minOccurs="0" />
<xs:element name="TaxTotal" type="xs:decimal" minOccurs="0" />