一个或多个元素,至少一个元素具有属性

时间:2015-10-08 13:22:25

标签: php xml xsd xsd-1.0

我需要在XML模式中描述以下内容:一个元素必须出现一次或多次,但该元素的恰好一次出现必须将属性“properties”设置为value“ NAV“

示例:

<manifest>
    <item href="example" id="02" properties="cover-image" /> <!-- optional item -->
    <item href="dummy" id="sample" properties="nav" /> <!-- mandatory item with "nav" value for "properties" attribute -->
    <item href="example" id="02" properties="mathlm scripted" /> <!-- optional item -->
</manifest> 

我的“最佳”尝试是:

    <xs:element name="manifest">
      <xs:complexType>
        <xs:choice>
          <xs:element name="item" minOccurs="1" maxOccurs="1" ><!-- at least one (item property="nav")-->
            <xs:complexType>
              <xs:attribute name="href" type="xs:string" use="required" />
              <xs:attribute name="id" type="xs:string" use="required" />
              <xs:attribute name="media-type" type="xs:string" use="required" />
              <xs:attribute name="fallback" type="xs:string" />
              <xs:attribute name="properties" type="xs:string" use="required" fixed="nav" />
              <xs:attribute name="media-overlay" type="xs:string" />
            </xs:complexType>
          </xs:element>
          <xs:element name="item" minOccurs="0" maxOccurs="unbounded" >
            <xs:complexType>
              <xs:attribute name="href" type="xs:string" use="required" />
              <xs:attribute name="id" type="xs:string" use="required" />
              <xs:attribute name="media-type" type="xs:string" use="required" />
              <xs:attribute name="fallback" type="xs:string" />
              <xs:attribute name="properties" type="xs:string" />
              <xs:attribute name="media-overlay" type="xs:string" />
            </xs:complexType>
          </xs:element>
        </xs:choice>
        <xs:attribute name="id" type="xs:string" />
      </xs:complexType>
    </xs:element>

不好尝试,因为验证器给了我以下错误:

  

本地复杂类型:内容模型不是决定论者。

很明显,这个模式不是确定性的,因为验证器无法决定是否应该使用此元素的2个定义中的第一个或第二个来检查遇到的item元素...
......但我怎样才能做到这一点?这有可能吗?

1 个答案:

答案 0 :(得分:3)

使用XSD 1.0无法实现,它需要XSD 1.1和断言。我不认为PHP中的默认模式验证器将支持XSD 1.1。

相关问题