2011-09-20 18 views
9

मैं अपने एक्सएमएल दस्तावेज़ को अपने एक्सएमएल स्कीमा के खिलाफ सत्यापित करने की कोशिश कर रहा हूं।एक्सएमएल स्कीमा सत्यापन: सीवीसी-कॉम्प्लेक्स-टाइप.2.4.ए

यह मेरा स्कीमा है:

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://cars.example.org/"> 
    <element name="cars"> 
    <complexType> 
     <sequence minOccurs="0" maxOccurs="unbounded"> 
     <element name="brand" type="string"/> 
     </sequence> 
    </complexType> 
    </element> 
</schema> 

और यह मेरा XML दस्तावेज़ है:

<?xml version="1.0" encoding="UTF-8"?> 
<cars xmlns="http://cars.example.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://cars.example.org/ cars.xsd"> 
    <brand>x</brand> 
</cars> 

अब जब मैं (ग्रहण के माध्यम से) दस्तावेज़ मैं लाइन 4 पर संदेश निम्न हो मान्य कर रहा हूँ:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'brand'. One of '{"":brand}' is expected. 

यह संदेश किसी भी भावना :(नहीं है। और यह बहुत मुश्किल गूगल समाधान के लिए (असंभव?) है।

आपकी मदद के लिए धन्यवाद।

उत्तर

11

आपका स्कीमा कोई नाम स्थान में होने के रूप में "ब्रांड" को परिभाषित किया गया है। '{"":brand}' का मतलब है। लेकिन आपके एक्सएमएल दस्तावेज़ में "ब्रांड" तत्व http://cars.example.org/ नामस्थान में है। इसलिए वे मेल नहीं खाते हैं और आपको अपनी सत्यापन त्रुटि मिलती है।

http://cars.example.org/ नामस्थान में होने के रूप में अपनी स्कीमा में "ब्रांड" तत्व घोषित करने के लिए, स्कीमा तत्व में elementFormDefault="qualified" विशेषता जोड़ें।

मेरा सुझाव है कि पूर्णता के लिए आप स्कीमा तत्व में attributeFormDefault="unqualified" भी जोड़ते हैं, हालांकि इस मामले में यह आपकी समस्या नहीं है।

0

आप कारों के भीतर विशेषता है, जो नाम स्थान का यूआरएल है विधिमान्य नहीं किया, यह काम करना चाहिए:

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
    elementFormDefault="qualified" 
    targetNamespace="http://cars.example.org/"> 
    <element name="cars"> 
    <complexType> 
     <sequence minOccurs="0" maxOccurs="unbounded"> 
     <element name="brand" type="string"/> 
     </sequence> 
     <attribute name="schemaLocation" type="anyURI"/> 
    </complexType> 
    </element> 
</schema> 
संबंधित मुद्दे