[英]XML schema for ordered child elements with different names
I need to Deserialize an XML that contains the definition of a Profile/polygon of points and arcs. 我需要反序列化XML,该XML包含点和弧的轮廓/多边形的定义。
<Pt>
<X>0.0</X>
<Y>0.0</Y>
</Pt>
<Arc>
<X>0.0</X>
<Y>0.0</Y>
<Rad>0.0</Rad>
</Arc>
Actual XML file: 实际的XML文件:
<Profile>
<Pt>...</Pt>
<Pt>...</Pt>
<Arc>...</Arc>
<Pt>...</Pt>
<Arc>...</Arc>
</Profile>
I am a little stuck finding a solution to know the order of child elements with different names. 我有点想找到一种解决方案来知道具有不同名称的子元素的顺序。 I am currently using something a schema that looks like the below code, but I obviously get individual arrays of Pts and Arcs without knowing the order of the Pts and Arcs.
我目前正在使用一种类似于以下代码的架构,但是显然我在不知道Pts和Arcs顺序的情况下得到了Pts和Arcs的单个数组。 I have tried creating a substitutionGroup (Point) that takes both Pt and Arc, but I was not successful.
我尝试创建一个同时包含Pt和Arc的替换组(点),但未成功。
<xs:element name="Profile">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Pt">
<xs:complexType>
<xs:sequence>
<xs:element name="X" type="xs:decimal" />
<xs:element name="Z" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="unbounded" name="Arc">
<xs:complexType>
<xs:sequence>
<xs:element name="X" type="xs:decimal" />
<xs:element name="Z" type="xs:decimal" />
<xs:element name="Rad" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
I suppose you want to permit an arbitrary order of your Pt
and Arc
elements. 我想您想允许
Pt
和Arc
元素的任意顺序。 The following schema will do the trick by setting maxOccurs="unbounded"
in the sequence
declaration. 以下模式将通过在
sequence
声明中设置maxOccurs="unbounded"
来解决问题。 You will also have to correct your Pt
and Arc
declarations since currently they are using Z
and not Y
as in your data. 您还必须更正
Pt
和Arc
声明,因为当前它们使用的是Z
而不是数据中的Y
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="pt-type">
<xs:sequence>
<xs:element name="X" type="xs:decimal" />
<xs:element name="Y" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="arc-type">
<xs:sequence>
<xs:element name="X" type="xs:decimal" />
<xs:element name="Y" type="xs:decimal" />
<xs:element name="Rad" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
<xs:element name="Profile">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:choice >
<xs:element name="Pt" type="pt-type"/>
<xs:element name="Arc" type="arc-type"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.