【发布时间】:2017-03-15 16:18:32
【问题描述】:
我正在使用 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。它只找到 Root 元素的声明。
XSNamedMap comp = model.getComponents(XSConstants.ELEMENT_DECLARATION);
也不起作用,它只返回 Root 声明。 如何让这些声明嵌套在 RootType 中?
【问题讨论】:
标签: xml xsd nested element xerces