问题描述
我的 XSD 架构中有以下复杂类型
I got the following complex type within my XSD schema
<xs:complexType name="structure" mixed="true">
<xs:choice maxOccurs="unbounded">
<xs:element type="b" name="b" />
<xs:element type="a" name="a" />
</xs:choice>
</xs:complexType>
它允许我像这样声明 XML 定义:
which allows me to state XML definitions like this:
<structure>
Hello <b>World</b>
Hello 2 <b>World 2</b>
<a>Hello3</a> <b>World3</b>
</structure>
现在我尝试从我的架构中生成 XSD 类,我尝试了 XSD.exe 和 XSD2Code.它们都生成类似
Now I tried to generate XSD classes out of my schema, I tried both XSD.exe as well as XSD2Code. They both generate something like
class structure {
List<a> a;
List<b> b;
List<string> text;
}
我的问题是,我需要跟踪在结构的 XML 内容中定义的元素的顺序.参考上面的例子,我想知道内部文本Hello"在b元素第一次出现之前就出现了.
My problem is, that I need to keep track in which order those elements where defined within the XML content of structure. Refering to the above example, I would like to know that the inner text "Hello" comes right before the first occurance of the b-element.
因为这显然需要更专业的生成器策略,也许我期望过高,但是:是否有任何 XSD 生成器可以处理对象顺序,或者我必须编写自己的类?
As this would obviously require a more specialized generator strategy, maybe I'm expecting too much, but: is there any XSD generator that can handle the object order or do I have to write my own classes?
提前致谢
推荐答案
我从未见过 XSD 到代码绑定工具可以满足您的需求,当然不是在 .NET 平台上 - 您似乎暗示为目标.这是 XML 往返是不可能的情况之一,不会丢失保真度(反序列化,序列化然后比较,它失败).为了完整起见,/order 选项不适用于 xsd.exe,因为就您定义的 XSD 而言,实际上没有顺序.这也是 XSD 可以描述的限制,这不可避免地反映在工具实现中.
I have never seen an XSD to code binding tool which would do what you need here, for sure not on the .NET platform - which you seem to imply as the target. This is one of those cases where roundtrip an XML is not possible, without loss of fidelity (deserialize, serialize then compare, it fails). Just for completeness, the /order option wouldn't work with xsd.exe, simply because in terms of the XSD you defined, there's no order really. It is, also, a limitation of what XSD can describe, which inevitably is reflected in tool implementations.
这篇关于XSD 类生成器:跟踪元素顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!