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>
我想獲取文件中每個元素的聲明,即:Root,ElementA,ElementB和ElementC。方法:
XSElementDeclaration decl = model.getElementDeclaration("ElementA");
爲ElementA,ElementB和ElementC返回null。它只找到根元素的聲明。
XSNamedMap comp = model.getComponents(XSConstants.ELEMENT_DECLARATION);
也不起作用,它只返回Root聲明。 如何讓這些聲明嵌套在RootType中?
謝謝,現在我得到它!但是,我遇到了另一個問題(我編輯了我的問題)。 –
請不要在獲得答案後更改問題,這會使線程非常難以遵循。如果您有其他問題,請在新線索中提出。 –
好吧,我已經撤消了更改。 –