xml 具有 ref 属性的平面目录架构

xml flat catalog schema with ref attribute

我正在使用带有 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>

您的 XML 对您当前所写的 XSD 无效是正确的。假设您希望更改您的 XSD 以使您的 XML 对其有效,这里有一些选项:

  • 在本地定义那些属性。
  • 将这些属性定义为其关联元素的全局定义类型的一部分。
  • 将这些属性定义为全局定义的一部分 xsd:attributeGroups