我正在尝试将 XML 文件(由模式验证)读入数据集的第一个数据表。这样做并在我的程序中放置一个断点后,我可以看到数据表有 0 行。我无法弄清楚为什么会这样......
这是代码示例:
Public Sub GitRDone(ByVal sqlDT As DataTable)
Dim ds As New DataSet
Dim appPath As String = GetAppPath()
Dim schemaFS As String = appPath & "blah.xsd"
Dim xmlFS As String = appPath & "blah.xml"
Try
ds.Clear()
ds.EnforceConstraints = False
ds.ReadXmlSchema(schemaFS)
ds.ReadXml(xmlFS)
ds.Tables.Add(sqlDT)
Catch e As Exception
MsgBox(e.ToString())
End Try
End Sub
架构示例:
<xsd:schema id="HCR_EmployeesSchema"
elementFormDefault="qualified"
targetNamespace="http://www.tempuri.org/MyDataSet.xsd"
xmlns="http://www.tempuri.org/MyDataSet.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="Employees" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Employee">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="EmployeeID">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:whiteSpace value="collapse"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
.....and on......
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
XML 示例:
<?xml version="1.0" encoding="utf-8"?>
<Employees>
<Employee>
<EmployeeID>blah</EmployeeID>
</Employee>
</Employees>