【问题标题】:order of parsed elements is lost in XMLBeansXMLBeans 中已解析元素的顺序丢失
【发布时间】:2009-06-10 12:41:33
【问题描述】:

我的 XML 结构有点像这样:

<root>
    <a/>
    <b/>
    <b/>
    <a/>
    <a/>
</root>

我的 XSD 如下所示:

<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:choice maxOccurs="unbounded">
                <xs:element ref="a"/>
                <xs:element ref="b"/>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:string" />

即我有两个不同子标签的随机序列。

使用 XMLBeans 我得到一个带有访问方法的 Root 对象: getAArray()、getBArray()

这是我的问题:
标签按名称分组,原始顺序 (a,b,b,a,a) 丢失。
但我需要知道这些元素的顺序

使用 XMLBeans 最好/最简单的方法是什么?

【问题讨论】:

    标签: java xml xmlbeans


    【解决方案1】:

    试试

    xml.selectPath("./*")

    【讨论】:

    • 正是我想要的。返回已解析的 XMLBean。非常感谢。
    【解决方案2】:

    好的,我明白了。 XmlObject 的 selectPath 方法返回一个对象数组,因此它给出了序列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 2021-01-09
      • 1970-01-01
      • 2017-06-24
      相关资源
      最近更新 更多