2017-03-15 9 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을 반환합니다. 루트 요소의 선언 만 찾습니다.

XSNamedMap comp = model.getComponents(XSConstants.ELEMENT_DECLARATION); 

도 작동하지 않으므로 루트 선언 만 반환합니다. 이러한 선언을 RootType에 중첩시키는 방법은 무엇입니까?

답변

1

스키마 구성 요소 모델을 재귀 적으로 검색해야합니다. 전역 요소 선언 (XSElementDeclaration)에서 getTypeDefinition()은 XSComplexTypeDefinition으로 이동합니다. getParticle()과 getTerm()을 사용하여 반복적으로 로컬 요소 선언을 나타내는 XSElementDeclaration 객체로 연결됩니다.

은 (색슨 SCM 파일은 기본적으로 동일한 데이터 구조를 포함하지만, 단계별 절차 탐색보다는 XPath 표현식을 사용하여, 당신에게 더 편리한 검색을 허용하는 XML 형식에.)

+0

덕분에, 지금은 얻을 그것! 그러나 다른 문제가 발생했습니다 (제 질문을 수정했습니다). –

+0

답변을 얻은 후에 질문을 변경하지 마십시오. 따라하기가 매우 어렵습니다. 다른 질문이있는 경우 새 스레드에서이를 제기하십시오. –

+0

좋아, 변경 사항을 취소했습니다. –