2013-10-19 11 views
5

में का कोई विकल्प है मेरे पास नीचे एक एक्सएसडी दस्तावेज़ खंड है। जब कोई XML फ़ाइल इस स्कीमा के विरुद्ध मान्य होती है, तो मैं यह सुनिश्चित करना चाहता हूं कि mm:Depot और mm:Customer/mm:County में मान समान है और Location प्रकार में आइटमों तक सीमित है। क्या एक्सएमएल स्कीमा 1.0

यह <assert> टैग का उपयोग कर एक्सएमएल स्कीमा 1.1 में किया जा सकता है लेकिन मुझे एक्सएमएल स्कीमा 1.0 के खिलाफ मान्य होना चाहिए। क्या यह काम 1.0 में करने के लिए कुछ साफ चाल है?

<xsd:element name="DeliveryOrder" type="OrderDetails" /> 

<xsd:complexType name="OrderDetails"> 
    <xsd:sequence> 
     <xsd:element name="Depot" type="mm:Location" /> 
     <xsd:element name="Customer" type="mm:Customer" maxOccurs="1" minOccurs="1" /> 
    </xsd:sequence> 
</xsd:complexType> 

<xsd:simpleType name="Location"> 
    <xsd:restriction base="xsd:string"> 
     <xsd:enumeration value="OverHere" /> 
     <xsd:enumeration value="OverThere" /> 
    </xsd:restriction> 
</xsd:simpleType> 

<xsd:complexType name="Customer"> 
    <xsd:sequence> 
     <xsd:element name="firstname" type="string" /> 
     <xsd:element name="surname" type="string" /> 
     <xsd:element name="County" type="mm:Location" /> 
    </xsd:sequence> 
</xsd:complexType> 

क्या मैं हासिल करना चाहते हैं कुछ इस तरह है ...

<?xml version="1.0" encoding="UTF-8"?> 
<mm:DeliveryOrder xmlns:mm="http://myNamespace/DeliveryOrderSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://myNamespace/DeliveryOrderSchema DeliveryOrder.xsd "> 

    <mm:Depot>OverThere</mm:Depot> 
    <mm:Customer> 
    <mm:firstname>Jane</mm:firstname> 
    <mm:surname>Doe</mm:surname> 
    <mm:County>OverThere</mm:County> 
    </mm:Customer> 
</mm:DeliveryOrder> 

नोट मूल्य OverThere दो बार प्रकट होता है।

उत्तर

1

आप "रेफरेंसियल अखंडता" का उपयोग कर सकते हैं।

<?xml version="1.0" encoding="utf-8" ?> 
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) --> 
<xsd:schema targetNamespace="http://myNamespace/DeliveryOrderSchema" xmlns="http://myNamespace/DeliveryOrderSchema" xmlns:mm="http://myNamespace/DeliveryOrderSchema" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:element name="DeliveryOrder" type="OrderDetails"> 
     <xsd:key name="LocationDepot"> 
      <xsd:selector xpath="mm:Depot"/> 
      <xsd:field xpath="."/> 
     </xsd:key> 
     <xsd:keyref refer="LocationDepot" name="CustomerLocation"> 
      <xsd:selector xpath="mm:Customer"/> 
      <xsd:field xpath="mm:County"/> 
     </xsd:keyref> 
    </xsd:element> 

    <xsd:complexType name="OrderDetails"> 
     <xsd:sequence> 
      <xsd:element name="Depot" type="Location"/> 
      <xsd:element name="Customer" type="Customer" maxOccurs="1" minOccurs="1"/> 
     </xsd:sequence> 
    </xsd:complexType> 

    <xsd:simpleType name="Location"> 
     <xsd:restriction base="xsd:string"> 
      <xsd:enumeration value="OverHere"/> 
      <xsd:enumeration value="OverThere"/> 
     </xsd:restriction> 
    </xsd:simpleType> 

    <xsd:complexType name="Customer"> 
     <xsd:sequence> 
      <xsd:element name="firstname" type="xsd:string"/> 
      <xsd:element name="surname" type="xsd:string"/> 
      <xsd:element name="County" type="Location"/> 
     </xsd:sequence> 
    </xsd:complexType> 
</xsd:schema> 

कोई त्रुटि के रूप में नीचे दिख सकता है:

Error occurred while loading [], line 10 position 3 The key sequence 'OverHere' in 'http://myNamespace/DeliveryOrderSchema:LocationDepot' Keyref fails to refer to some key.

संबंधित मुद्दे