2012-06-22 12 views
7

मेरे पास एक एक्सएमएल और एक्सएसडी फ़ाइल है जो दोनों सही ढंग से मान्य (http://xsdvalidation.utilities-online.info/ पर परीक्षण)।

हालांकि, एक्सएमएल xsd के खिलाफ मान्य नहीं है। मुझे लगता है कि ऐसा इसलिए है क्योंकि मैं xml की तुलना में xsd में जटिल टाइप टाइप तत्वों को गलत तरीके से घोंसला कर रहा हूं। people के बाहरी तत्व समस्या उत्पन्न कर रहा है ...

यहाँ एक्सएमएल है:
आप xsd में जटिल प्रकार टाइप तत्वों को कैसे घोंसला करते हैं?

<?xml version = "1.0"?> 

<people> 
    <person> 
     <firstname>Joe</firstname> 
     <lastname>Schmoe</lastname> 
    </person> 

    <person> 
     <firstname>Cletus</firstname> 
     <lastname>Jenkins</lastname> 
    </person> 
</people> 

... और यहाँ XSD है:

<?xml version = "1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:element name = "people"> 
     <xs:complexType> 
      <xs:sequence> 

       <xs:element name = "person"> 
        <xs:complexType> 
         <xs:sequence> 

          <xs:element name = "firstname" type = "xs:string" /> 
          <xs:element name = "lastname" type = "xs:string" /> 

         </xs:sequence> 
        </xs:complexType> 
       </xs:element> 

      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 

</xs:schema> 

उत्तर

10

"व्यक्ति" नामक तत्व में maxoccurs="unbounded" जोड़ें। यह एक या अधिक व्यक्ति तत्वों का अनुक्रम है।

+0

अरे, तुम सही हो, मेरा उत्तर :-) –

+0

आह की अनदेखी, कि एक सरल उपाय, उसके लिए धन्यवाद है! –

2

अपने XSD के लिए इस प्रयास करें:

<?xml version = "1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:element name="people" type="people"/> 

    <xs:complexType name="people"> 
     <xs:sequence> 
      <xs:element name="person" type="person" maxOccurs="unbounded" minOccurs="0"/> 
     </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="person"> 
     <xs:sequence> 
      <xs:element name="firstname" type="xs:string" maxOccurs="1" minOccurs="1"/> 
      <xs:element name="lastname" type="xs:string" maxOccurs="1" minOccurs="1"/> 
     </xs:sequence> 
    </xs:complexType> 

</xs:schema> 
+0

बीटीडब्ल्यू, मैंने कुछ तत्वों की घटनाओं की संख्या के लिए कुछ उदाहरण प्रतिबंध जोड़े हैं, लेकिन निश्चित रूप से इन्हें आपकी आवश्यकताओं के आधार पर बदला या छोड़ा जा सकता है। –

+0

यह एक दिलचस्प समाधान @ जोनोब है ... क्या यह हमेशा < ... 'टैग? –

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