【发布时间】:2016-10-07 16:37:09
【问题描述】:
我正在尝试生成 XSD 以验证具有未知深度的 XML。这是通过 XML 中的 XSLT 完成的。 XML 的结构有点像类描述,每个节点都包含有关属性和子节点的信息。 XSD 必须检查另一个包含实例的 XML。所以 XSD 必须检查一个实例是否具有它的类和它的祖先的所有属性。
这就是为什么我试图用相互扩展的类型来解决我的问题。
XML 测试文件:
<!-- language:xml -->
<?xml version="1.0" encoding="UTF-8"?>
<CAEXFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
FileName="Visu_Ruehrreaktor.aml"
SchemaVersion="2.15"
xsi:noNamespaceSchemaLocation="Validation.xsd">
<HMI>
<HMIGraphic Name="Visu_Ruehrreaktor"
RefBaseSystemUnitPath="HMISUCLib/Graphic"
ID="dce863ca-795b-4d54-9a4c-789b0204f243">
<h>1080</h>
<w>1920</w>
<HMIVisuObjectTextBoxTermination Name="Text01"
RefBaseSystemUnitPath="HMISUCLib/VisuObject/TextBox/Termination"
ID="c0215848-b8b6-4f76-aa2c-3996a053f3fc">
<text/>
<tagname>Text01</tagname>
<x>178</x>
<y>152</y>
<h>37</h>
<w>139</w>
<role/>
<type>0001</type>
<rotation>01</rotation>
<com_id/>
</HMIVisuObjectTextBoxTermination>
</HMIGraphic>
</HMI>
</CAEXFile>
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xs:complexType name="HMI_type">
<xs:choice maxOccurs="unbounded">
<xs:element name="HMIGraphic" type="HMIGraphic_type" minOccurs="0"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="HMIVisuObject_type">
<xs:choice maxOccurs="unbounded">
<xs:element name="tagname" minOccurs="1" maxOccurs="1"/>
<xs:element name="x" minOccurs="1" maxOccurs="1"/>
<xs:element name="y" minOccurs="1" maxOccurs="1"/>
<xs:element name="h" minOccurs="1" maxOccurs="1"/>
<xs:element name="w" minOccurs="1" maxOccurs="1"/>
<xs:element name="role" minOccurs="1" maxOccurs="1"/>
<xs:element name="type" minOccurs="1" maxOccurs="1"/>
<xs:element name="rotation" minOccurs="1" maxOccurs="1"/>
</xs:choice>
<xs:attribute name="Name" type="xs:string" use="required"/>
<xs:attribute name="RefBaseSystemUnitPath" type="xs:string" use="required"/>
<xs:attribute name="ID" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="HMIVisuObjectTextBox_type">
<xs:complexContent>
<xs:extension base="HMIVisuObject_type">
<xs:choice maxOccurs="unbounded">
<xs:element name="text" minOccurs="1" maxOccurs="1"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="HMIVisuObjectTextBoxTermination_type">
<xs:complexContent>
<xs:extension base="HMIVisuObjectTextBox_type">
<xs:choice maxOccurs="unbounded">
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="HMIGraphic_type">
<xs:choice maxOccurs="unbounded">
<xs:element name="HMIVisuObject" type="HMIVisuObject_type" minOccurs="0"/>
<xs:element name="HMIVisuObjectTextBox"
type="HMIVisuObjectTextBox_type"
minOccurs="0"/>
<xs:element name="HMIVisuObjectTextBoxTermination"
type="HMIVisuObjectTextBoxTermination_type"
minOccurs="0"/>
<xs:element name="h" minOccurs="1" maxOccurs="1"/>
<xs:element name="w" minOccurs="1" maxOccurs="1"/>
</xs:choice>
<xs:attribute name="Name" type="xs:string" use="required"/>
<xs:attribute name="RefBaseSystemUnitPath" type="xs:string" use="required"/>
<xs:attribute name="ID" type="xs:string" use="required"/>
</xs:complexType>
<xs:element name="CAEXFile">
<xs:complexType>
<xs:all>
<xs:element name="HMI" type="HMI_type" minOccurs="0"/>
</xs:all>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:schema>
问题是,当我运行验证并找到类型为 HMIVisuObjectTextBoxTermination_type 的元素时,我收到一条错误消息,指出不允许将 text 作为元素。 p>
输出/To_Check.aml:15:元素文本:架构有效性错误:元素“文本”:不需要此元素。预期是(标记名、x、y、h、w、角色、类型、旋转)之一。
所以基本上只有这个类型链的根元素的元素。我做错了什么,我该如何解决这个问题。
提前致谢
【问题讨论】:
-
添加了两个文件。我希望它有所帮助。
标签: xml xslt xsd xsd-validation