gpt4 book ai didi

xml - 如何在 XML 中创建有序数据

转载 作者:数据小太阳 更新时间:2023-10-29 02:41:44 25 4
gpt4 key购买 nike

我想将多边形定义为一系列点,如下所示:

<polygon>
<point x="0" y="0" z="0" />
<point x="100.0" y="100.0" z="100.0" />
<point x="50.0" y="100.0" z="50.0" />
</polygon>

重要的是在我读入时保留点的顺序

我编写了以下 xsd 文件:

<xs:element  name="point_type">
<xs:complexType>
<xs:attribute name="x" type="xs::double"/>
<xs:attribute name="y" type="xs::double"/>
<xs:attribute name="z" type="xs::double"/>
</xs:complexType>
</xs:element>

<xs:element name="polygon_type">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="point" type="point_type"/>
</xs:sequence>
</xs:complexType>
</xs:element>

但有人注意到 xs:sequence并不一定意味着 <points>会井然有序。事实上,http://www.w3schools.com/schema/el_sequence.asp似乎定义了那个序列

    <xs:sequence maxOccurs="unbounded">
<xs:element name="A" type="A_type"/>
<xs:element name="B" type="B_type"/>
</xs:sequence>

只会确保BA 之后的

<super>
<A/>
<B/>
<A/>
<B/>
</super>

并且没有说明 {A-B} 对的顺序。

有人知道吗?你能指出支持一个论点或另一个论点的引用资料吗?

最佳答案

我建议您向点添加一个 id 属性,这样您就可以明确地跟踪点在您的应用程序中的顺序,而不是依赖 XML 解析器以正确的顺序返回元素。我使用过的所有 XML 解析器都遵循元素顺序,但我在 XML spec 中找不到任何内容。关于这个。

<polygon>
<point id="0" x="0" y="0" z="0" />
<point id="1" x="100.0" y="100.0" z="100.0" />
<point id="2" x="50.0" y="100.0" z="50.0" />
</polygon>

关于xml - 如何在 XML 中创建有序数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12623525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com