2011-09-20 20 views
9

私のXMLスキーマに対して自分のXML文書を検証しようとしています。XMLスキーマ検証:cvc-complex-type.2.4.a

これは私のスキーマです:

<?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行目にメッセージを以下取得(Eclipseの経由)文書を検証していたときに:

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

このメッセージは、:(どんな意味がありません。そして、それは非常に難しい(不可能?)Googleのソリューションへ。

ありがとうございます。

答えて

11

あなたのスキーマがありません名前空間にあるものとして、「ブランド」を定義しています。それは'{"":brand}'の意味です。しかしXML文書では、 "brand"要素はhttp://cars.example.org/名前空間にあります。だから彼らは一致しないし、あなたの検証エラーを取得します。

スキーマの "brand"要素をhttp://cars.example.org/名前空間として宣言するには、スキーマ要素にelementFormDefault="qualified"という属性を追加します。

完全性のために、attributeFormDefault="unqualified"もスキーマ要素に追加することをお勧めしますが、この場合は問題はありません。

0

あなたは、これは動作するはずです、名前空間のURLである、自動車内の属性を検証していない:

<?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> 
関連する問題