XML 验证 C# - 复杂类型
我正在从 XFA 静态表单中提取一些 xml。 下面是一个示例:
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
<frmMain>
<InspectionDate>19/02/2012</InspectionDate>
<ENID>111114567</ENID>
<EmployeeNumber>1234</EmployeeNumber>
<GroundType>
<value>Tarmac</value>
<value>Concrete</value>
</GroundType>
<Width>800</Width>
<Height>900</Height>
<OtherDetails>Corssing of x road and y street</OtherDetails>
</frmMain>
</xfa:data>
</xfa:datasets>
我使用 Windows SDK 7.0 实用程序 Xsd.exe 生成架构,以便我可以根据该 XML 进行验证 如下:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="datasets" targetNamespace="http://www.xfa.org/schema/xfa-data/1.0/" xmlns:mstns="http://www.xfa.org/schema/xfa-data/1.0/" xmlns="http://www.xfa.org/schema/xfa-data/1.0/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:attribute name="dataNode" msdata:Prefix="xfa" type="xs:string" />
<xs:element name="datasets" msdata:IsDataSet="true" msdata:Locale="en-US" msdata:Prefix="xfa">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="data" msdata:Prefix="xfa">
<xs:complexType>
<xs:sequence>
<xs:element name="frmMain" form="unqualified">
<xs:complexType>
<xs:sequence>
<xs:element name="InspectionDate" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="ENID" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="EmployeeNumber" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="Width" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="Height" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="OtherDetails" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="GroundType" form="unqualified" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute ref="mstns:dataNode" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
我使用 XmlReaderSettings 和 XmlReader 来读取 Xml 并针对 Xsd 进行验证。只要我没有复杂的类型,一切都可以。但在这种情况下我有。
可以做什么?
我得到的错误是:
元素“GroundType”不能包含子元素“value”,因为父元素的内容模型为空。
I'm extracting some xml from an XFA static form.
Here is a sample:
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
<frmMain>
<InspectionDate>19/02/2012</InspectionDate>
<ENID>111114567</ENID>
<EmployeeNumber>1234</EmployeeNumber>
<GroundType>
<value>Tarmac</value>
<value>Concrete</value>
</GroundType>
<Width>800</Width>
<Height>900</Height>
<OtherDetails>Corssing of x road and y street</OtherDetails>
</frmMain>
</xfa:data>
</xfa:datasets>
I use Windows SDK 7.0 utility Xsd.exe to generate a schema so I can validate that XML against
Here it is:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="datasets" targetNamespace="http://www.xfa.org/schema/xfa-data/1.0/" xmlns:mstns="http://www.xfa.org/schema/xfa-data/1.0/" xmlns="http://www.xfa.org/schema/xfa-data/1.0/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:attribute name="dataNode" msdata:Prefix="xfa" type="xs:string" />
<xs:element name="datasets" msdata:IsDataSet="true" msdata:Locale="en-US" msdata:Prefix="xfa">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="data" msdata:Prefix="xfa">
<xs:complexType>
<xs:sequence>
<xs:element name="frmMain" form="unqualified">
<xs:complexType>
<xs:sequence>
<xs:element name="InspectionDate" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="ENID" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="EmployeeNumber" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="Width" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="Height" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="OtherDetails" form="unqualified" type="xs:string" minOccurs="0" />
<xs:element name="GroundType" form="unqualified" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute ref="mstns:dataNode" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
I use XmlReaderSettings with a XmlReader to read and validate the Xml against the Xsd. Everything is ok as long as I do not have a complex type. But in this case I have.
What can be done?
And the Error I'm getting is:
The element 'GroundType' cannot contain child element 'value' because the parent element's content model is empty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 GroundType 定义应如下所示:
Your GroundType definition should look like this: