2017-03-15 4 views
0

Apache Xercesを使用して、次のXSDファイルを解析しています。Apache Xercesはxsdのすべての要素の宣言を取得します

<xs:element name="Root" type="RootType"> 
    ... 
</xs:element> 

<xs:complexType name="RootType"> 
    <xs:complexContent> 
     <xs:extension base="BaseElement"> 
      <xs:choice maxOccurs="unbounded"> 
       <xs:element name="ElementA" type="ElementAType" /> 
       <xs:element name="ElementB" type="ElementBType" /> 
       <xs:element name="ElementC" type="ElementCType" /> 
      </xs:choice> 

      <xs:attribute ... >...</xs:attribute> 
      <xs:attribute ... >...</xs:attribute> 
      <xs:attribute ... >...</xs:attribute> 
     </xs:extension> 
    </xs:complexContent> 
</xs:complexType> 

<xs:complexType name="BaseElement"> 
    ... 
</xs:complexType> 

<xs:complexType name="ElementAType"> 
    ... 
</xs:complexType> 

<xs:complexType name="ElementBType"> 
    ... 
</xs:complexType> 

<xs:complexType name="ElementCType"> 
    ... 
</xs:complexType> 

私は、ファイル内のすべての要素の宣言を取得したいと思います:ルート、ElementA、ElementBとElementCを。メソッド:

XSElementDeclaration decl = model.getElementDeclaration("ElementA"); 

は、ElementA、ElementBおよびElementCに対してnullを返します。 Root要素の宣言だけが見つかります。

も動作しません。ルート宣言のみが返されます。 これらの宣言をRootTypeにネストする方法は?

答えて

1

スキーマコンポーネントモデルを再帰的に検索する必要があります。グローバル要素宣言(XSElementDeclaration)から、getTypeDefinition()はXSComplexTypeDefinitionに移動します。 getParticle()とgetTerm()を使用して再帰的にそこからローカル要素宣言を表すXSElementDeclarationオブジェクトに到達します。

は(サクソンSCMファイルは、基本的に同じデータ構造が含まれているが、ステップ・バイ・ステップの手続きナビではなく、XPath式を使用して、あなたがより便利に検索することができますXML形式で。)

+0

おかげで、今私が取得しますそれ!しかし、別の問題が発生しました(私は質問を編集しました)。 –

+0

答えを得た後に質問を変更しないでください。それはスレッドを非常に難しくします。別の質問がある場合は、新しいスレッドでそれを上げてください。 –

+0

私は変更を元に戻しました。 –

関連する問題