2011-06-19 14 views
7

क्या यह भी संभव है?मैं एक विशेषता के लिए एक तत्व निर्दिष्ट कैसे कर सकता हूं जिसमें यह बताता है कि एक्सएमएल स्कीमा में कितने बच्चे हैं?

  • मैं जानता हूँ कि यह regex के आधार पर एक प्रतिबंध करना संभव है, लेकिन वह नहीं यह
  • मैं जानता हूँ कि यह एक XPath द्वारा गणना एक विदेशी कुंजी के रूप में एक विशेषता घोषित करने के लिए संभव है, लेकिन ऐसा लगता है यह अनूठा हो गया है

उदाहरण:

<root children="2"> 
    <child /> 
    <child /> 
</root> 

उत्तर

5

W3C स्कीमा 1.0 उदाहरण पर आधारित विशेषता मान विवश करने की क्षमता नहीं है दस्तावेज़।

Schematron ऐसे दस्तावेजों को मान्य करने के लिए एक महान उपकरण है जो इस तरह के कस्टम सत्यापन परिदृश्यों का पालन करता है।

उदाहरण के लिए:

<xs:element name="root"> 
    <xs:complexType> 
    <xs:sequence> 
     <xs:element name="child" maxOccurs="unbounded"/> 
    </xs:sequence> 
    <xs:attribute name="children" type="xs:integer"/> 
    </xs:complexType> 
    <xs:assert test="@children = count(child)"/> 
</xs:element> 

XSD 1.1 वर्तमान में सैक्सन और Xerces में कार्यान्वित किया जाता:

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://purl.oclc.org/dsdl/schematron"> 
    <pattern> 
     <rule context="root[@children]"> 
      <assert 
       id="children-value" 
       test="@children=count(child)" 
       flag="error"> 
       The root/@children value must be equal to the number of child elements. 
       </assert> 
      </rule> 
    </pattern> 
</schema> 
+0

यही मैंने सोचा, धन्यवाद। – sebastien

6

XSD 1.1 आप बाधा इस तरह व्यक्त करने के लिए अनुमति देता है।