2011-03-02 5 views
6

私はXMLスキーマの基本的な理解しか持っていません。これは基本的に私の最初のやりとりであり、私はいくつかの問題を抱えています。私はgoogleでXSDを読んだことがあります。ここでこのXMLスキーマに根本的に何か間違っていますか?

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

    <xs:element name="credits"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element ref="property" maxOccurs="16" minOccurs="13" /> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 

    <xs:element name="property" type="xs:string">  
    <xs:complexType>   
     <xs:sequence>    
      <xs:element ref="item" minOccurs="1" maxOccurs="unbounded" /> 
     </xs:sequence> 
     <xs:attribute ref="name" use="required"/> 
    </xs:complexType> 

    </xs:element> 

    <xs:element name="item" type="xs:string"/> 

    <xs:attribute name="name" type="xs:string"> 
     <xs:simpleType> 
     <xs:restriction base="xs:string"> 
      <xs:enumeration value="example1"/> 
      <xs:enumeration value="example2"/> 
      <xs:enumeration value="example3"/> 
      <xs:enumeration value="example4"/> 
      <xs:enumeration value="example5"/> 
      <xs:enumeration value="example6"/> 
      <xs:enumeration value="example7"/> 
      <xs:enumeration value="example8"/> 
      <xs:enumeration value="example9"/> 
      <xs:enumeration value="example10"/> 
      <xs:enumeration value="example11"/> 
      <xs:enumeration value="example12"/> 
      <xs:enumeration value="example13"/> 
      <xs:enumeration value="example14"/> 
      <xs:enumeration value="example15"/> 
      <xs:enumeration value="example16"/> 
     </xs:restriction> 
     </xs:simpleType> 
    </xs:attribute> 

</xs:schema> 

は、私はそれをロードしています方法は次のとおりです。

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
Schema schemaXSD = schemaFactory.newSchema(new File ("test.xsd")); 

私は次のような例外を取得しています:

org.xml.sax.SAXParseExceptionを: src-element.3: 'property'要素には 'type'属性と 'anonyの両方の がありますマイズタイプの子供。要素には のいずれか1つのみが許可されます。

ありがとうございました!他の人が作成したスキーマの読み書きに関する一般的なアドバイスもありがとうございます! :D

+0

を削除するのいずれかのIDEの数があります。この種のエラーは、編集時に(つまり、あなた自身のコードにXSDを提出する前に)見つけることができます。 [eclipse J2E](http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/heliossr1)の例では、あなたが引用したのと同じエラーメッセージが表示され、右端に小さな赤いマーカーが表示されます) )。 –

答えて

5

このビットは、あなたの問題のコードです:

<xs:element name="property" type="xs:string">  
    <xs:complexType>   
     <xs:sequence>    
      <xs:element ref="item" minOccurs="1" maxOccurs="unbounded" /> 
     </xs:sequence> 
     <xs:attribute ref="name" use="required"/> 
    </xs:complexType> 

    </xs:element> 

外部要素(type="xs:string")上のタイプを削除するか、匿名の内部complexType要素(<xs:complexType> ... </xs:complexType>

+2

これはおそらくコードの次のビットにも現れます。 あなたは2つの型宣言を持っており、システムはどちらを使うべきかを知らないでしょう。 – blueberryfields

+0

次に、要素にcompletypeを使用しない属性があることをどのように伝えますか? – Ashwin

6

要素「プロパティが」「type」属性と「匿名型」子つまり

の両方を持っている、あなたはtype="xs:string"を言うと、これは<property>foo</property>ようなノードを規定しています。しかし、あなたはpropertyの中にComplexType itemを入れて、<property><item>...</item></property>のようなノードを規定します。これはパーサがエラーとみなす矛盾です。

あなたは、どちらかのタグが付けられた子、またはpropertyの属性、別のノードとしてこの文字列を格納し、各propertypropertyごとに1つの別個の文字列をitem秒数を格納する場合。例えば。 <property mystring="foo"><item>...</item></property>

+0

次に、要素が完全型を使用しない属性を持つことをどのように伝えますか?私は、属性にcomplexTypeの中に要素が含まれていなければならないと考えました。 – Ashwin

関連する問題