【问题标题】:xml flat catalog schema with ref attribute带有 ref 属性的 xml 平面目录架构
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 2017-03-08
    相关资源
    最近更新 更多