【发布时间】:2016-03-16 12:44:03
【问题描述】:
我使用带有 XMLEspresso 插件的 eclipse mars。 问题是我可以引用属性还是必须将其放入元素中。 eclipse 的验证表明,flughafen 中的 id 不能与所有其他属性相同。
XML- 示例:
<?xml version="1.0" encoding="UTF-8"?>
<flugplan xmlns="http://example.org/Flugplan"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.org/Flugplan Flugplan-flat.xsd ">
<flughafen id="DUS" name="Düsseldorf" land="D" />
<flughafen id="HAM" name="Hamburg" land="D" />
<flughafen id="LHR" name="London/Heathrow" land="GB" />
<flughafen id="MUC" name="München" land="D" />
<flughafen id="WAW" name="Warschau" land="PL" />
<type id="A319" reichweite="6801" />
<type id="A321" reichweite="5600" />
<type id="CRJ9" reichweite="2100" />
<type id="DH8D" reichweite="1520" />
<maschine code="D-AIDW" type="A321" />
<maschine code="D-ACNN" type="CRJ9" />
<maschine code="SP-EQB" type="DH8D" />
<maschine code="D-AIDX" type="A321" />
<maschine code="D-AGWM" type="A319" />
<flug code="EW4462" start="HAM" ziel="LHR" abflug="07:30" entfernung="746" />
<flug code="LH2085" start="HAM" ziel="MUC" abflug="07:30" entfernung="601" />
<flug code="L0402" start="HAM" ziel="WAW" abflug="07:35" entfernung="754" />
<flug code="LH2087" start="HAM" ziel="MUC" abflug="08:00" entfernung="601" />
<flug code="4U9031" start="HAM" ziel="DUS" abflug="08:20" entfernung="340" />
<einsatz flug="EW4462" maschine="D-ACNN" />
<einsatz flug="LH2085" maschine="D-AIDW" />
<einsatz flug="L0402" maschine="SP-EQB" />
<einsatz flug="LH2087" maschine="D-AIDX" />
<einsatz flug="4U9031" maschine="D-AGWM" />
</flugplan>
Xml 架构:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.org/Flugplan"
xmlns="http://example.org/Flugplan"
elementFormDefault="qualified">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="land" type="xsd:string" />
<xsd:attribute name="reichweite" type="xsd:string" />
<xsd:attribute name="code" type="xsd:string" />
<xsd:attribute name="typ" type="xsd:string" />
<xsd:attribute name="start" type="xsd:string" />
<xsd:attribute name="ziel" type="xsd:string" />
<xsd:attribute name="abflug" type="xsd:string" />
<xsd:attribute name="entfernung" type="xsd:integer" />
<xsd:attribute name="flug" type="xsd:string" />
<xsd:attribute name="maschine" type="xsd:string" />
<xsd:element name="flughafen">
<xsd:complexType>
<xsd:attribute ref="id" />
<xsd:attribute ref="name" />
<xsd:attribute ref="land" />
</xsd:complexType>
</xsd:element>
<xsd:element name="type">
<xsd:complexType>
<xsd:attribute ref="id" />
<xsd:attribute ref="reichweite" />
</xsd:complexType>
</xsd:element>
<xsd:element name="maschine">
<xsd:complexType>
<xsd:attribute ref="code" />
<xsd:attribute ref="typ" />
</xsd:complexType>
</xsd:element>
<xsd:element name="flug">
<xsd:complexType>
<xsd:attribute ref="code" />
<xsd:attribute ref="start" />
<xsd:attribute ref="ziel" />
<xsd:attribute ref="abflug" />
<xsd:attribute ref="entfernung" />
</xsd:complexType>
</xsd:element>
<xsd:element name="einsatz">
<xsd:complexType>
<xsd:attribute ref="flug" />
<xsd:attribute ref="maschine" />
</xsd:complexType>
</xsd:element>
<xsd:element name="flugplan">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="flughafen" minOccurs="1" maxOccurs="unbounded" />
<xsd:element ref="type" minOccurs="1" maxOccurs="unbounded" />
<xsd:element ref="maschine" minOccurs="1" maxOccurs="unbounded" />
<xsd:element ref="flug" minOccurs="1" maxOccurs="unbounded" />
<xsd:element ref="einsatz" minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
【问题讨论】:
-
说得对..那你的问题是什么?
-
好吧,平面目录仍然可以引用每个元素,因此您可以多次使用它。此外,我想多次使用该属性,例如“id”,并且不必为每个具有 id 属性的元素标注类型。问题是我是否在架构中犯了错误,或者引用属性或验证插件是否存在错误是不正确的?
标签: xml validation xsd catalog flat