鑑於這種XML模式(片段):序列模式元素是否保證子元素的順序?
<xs:element name="GetIEnumerableResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="GetIEnumerableResult" nillable="true" xmlns:q4="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q4:ArrayOfstring" />
</xs:sequence>
</xs:complexType>
</xs:element>
在該XML片段:
<ArrayOfstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<string>string1</string>
<string>string2</string>
<string>string3</string>
</ArrayOfstring>
可以在<串> < /串>元件以任何順序出現?因此,是XML的這些兩個片段語義等同放着清單:
<ArrayOfstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<string>string1</string>
<string>string2</string>
<string>string3</string>
</ArrayOfstring>
<ArrayOfstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<string>string3</string>
<string>string2</string>
<string>string1</string>
</ArrayOfstring>
抑或架構中的序列元件意味着<串> < /串>元件具有以相同的順序是語義上等同於發生?
模式中的存在是否需要解析器/反序列化器使元素保持其在xml文本中存在的順序?如果我理解正確,通常(即沒有模式)不需要這樣做(即使大多數解析器通常都這樣做)。
優秀的答案,序列化索引確實是我使用的原始解決方案。我創建了一個「OrderedList」類,該類基本上是一個字典,其中int是索引。顯然這是正確的答案。 –
Mark
2009-08-26 18:13:05