我试图生成一个XSD来验证具有未知深度的XML。这是通过来自XML的XSLT完成的。 XML有点类似于类的描述,每个节点都包含有关属性和子节点的信息。 XSD必须检查另一个包含实例的XML。因此,XSD必须检查一个实例是否具有来自其类的所有属性,并且它是祖先。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我得到一个错误,说文本不允许作为元素。
输出/ To_Check.aml:15:元素文本:模式有效性错误:元素'文本':该元素不是期望的。预期是(标记名,x,y,h,w,角色,类型,旋转)之一。
所以基本上只有这个类型链的根元素的元素。我做错了什么,我怎么能解决这个问题。
由于提前
添加了这两个文件。我希望它有帮助。 – Tyreal