【发布时间】:2015-09-19 01:27:42
【问题描述】:
我认为这应该工作......但它不是!这是我的 XSD:
<xsd:schema targetNamespace="http://www.loc.gov/MARC21/slim" xmlns="http://www.loc.gov/MARC21/slim"
xmlns:xerces="http://xerces.apache.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.1" xml:lang="en">
<xsd:element name="record" type="recordType" nillable="true" id="record.e"/>
<xsd:element name="collection" type="collectionType" nillable="true" id="collection.e"/>
<xsd:complexType name="collectionType" id="collection.ct">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="record"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="recordType" id="record.ct">
<xsd:sequence minOccurs="0">
<xsd:element name="datafield" type="dataFieldType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="type" type="recordTypeType" use="optional"/>
<xsd:assert test="count(./datafield[@tag = '100']) = 1"
xerces:message="A record must only have up to one 1XX field"/>
</xsd:complexType>
<xsd:simpleType name="recordTypeType" id="type.st">
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="Bibliographic"/>
<xsd:enumeration value="Authority"/>
<xsd:enumeration value="Holdings"/>
<xsd:enumeration value="Classification"/>
<xsd:enumeration value="Community"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="dataFieldType" id="datafield.ct">
<xsd:attribute name="tag" type="tagDataType" use="required"/>
<xsd:attribute name="ind1" type="indicatorDataType" use="required"/>
<xsd:attribute name="ind2" type="indicatorDataType" use="required"/>
<xsd:assert
test="not((@tag = '100' or @tag = '110' or @tag = '111' or @tag = '130') and not(@ind2 = ' '))"
xerces:message="1XX fields must have a blank 2nd indicator">
<xsd:annotation>
<xsd:documentation xml:lang="en">This assertation ensures that the second indicator
of a 1XX field is blank.</xsd:documentation>
</xsd:annotation>
</xsd:assert>
</xsd:complexType>
<xsd:simpleType name="tagDataType" id="tag.st">
<xsd:restriction base="xsd:string">
<xsd:whiteSpace value="preserve"/>
<xsd:pattern
value="010|020|040|042|050|082|100|110|111|130|245|246|250|260|264|300|336|337|338|500|505|520|490|600|610|611|630|650|655|700|710|711|730|830|856"
/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="indicatorDataType" id="ind.st">
<xsd:restriction base="xsd:string">
<xsd:whiteSpace value="preserve"/>
<xsd:pattern value="[\da-z ]{1}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
这是我的 XML 数据:
<collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/MARC21/slim file:/Users/NetanelGanin/Desktop/Test.xsd"
xmlns="http://www.loc.gov/MARC21/slim">
<record type="Bibliographic">
<datafield tag="010" ind1=" " ind2=" "/>
<datafield tag="020" ind1=" " ind2=" "/>
<datafield tag="040" ind1=" " ind2=" "/>
<datafield tag="042" ind1=" " ind2=" "/>
<datafield tag="050" ind1="0" ind2="0"/>
<datafield tag="082" ind1="0" ind2="0"/>
<datafield tag="100" ind1="1" ind2=" "/>
<datafield tag="245" ind1="1" ind2="0"/>
</record>
</collection>
第二个断言工作正常! (每当我通过使 @ind2 不是空格来测试它时),但第一个断言总是失败。我什至尝试过写:
<xsd:assert test="./datafield"/>
只是说,“嘿,如果有一个名为 datafield 的子元素,然后传递断言,”它失败了!
想法?
【问题讨论】: