Ich versuche, eine XSD zu generieren, um eine XML mit einer unbekannten Tiefe zu validieren. Dies geschieht über ein XSLT aus einem XML. Der XML-Code ist wie eine Klassenbeschreibung strukturiert und jeder Knoten enthält Informationen über die Attribute und Childs. Das XSD muss ein anderes XML überprüfen, das die Instanzen enthält. Daher muss das XSD überprüfen, ob eine Instanz alle Attribute von ihrer Klasse und ihren Vorfahren hat.XSD Probleme mit Erweiterung über mehrere Ebene
Deshalb habe ich versucht, mein Problem mit Typen zu lösen, die sich gegenseitig erweitern.
XML-Testdatei:
<!-- 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>
Das Problem ist, wann immer ich die Validierung laufen und ein Element des Typs HMIVisuObjectTextBoxTermination_type ich sagen, erhalten Sie einen Fehler finden, dass Der Text ist nicht als Element zulässig.
Ausgabe/To_Check.aml: 15: Elementtext: Schema-Gültigkeitsfehler: Element 'text': Dieses Element wird nicht erwartet. Erwartet wird (Tagname, x, y, h, w, Rolle, Typ, Rotation).
Also im Grunde nur die Elemente des Wurzelelements dieser Kette von Typen. Was mache ich falsch und wie kann ich dieses Problem lösen?
Vielen Dank im Voraus
Beide Dateien hinzugefügt. Ich hoffe, es hilft. – Tyreal