作为特定复杂类型的扩展的任何类型元素的 xsd 序列 [英] xsd sequence of any type of element that is an extension of specific complex type
问题描述
基本上,如果这是 .NET,它看起来像这样:
Basically if this was .NET, it would look like this:
ISomething
{
string A { get; }
int B { get; }
}
var somethings = new List<ISomething>();
something.Add(new SomethingSomething());
something.Add(new AnotherSomething());
something.Add(new AnythingSomething());
基本上我希望元素序列可以任意命名,只要它们的复杂类型是我定义的复杂类型的扩展.
Basically I want the sequence of elements to be named anything they want to be, as long as their complex type is an extension of a complex type I define.
所以它可能看起来像:
<somethings>
<something-something a="foo" b="0" />
<another-something a="bar" b="1" />
<example:anything-something a="baz" b="2" />
</somethings>
我确定这是可能的,我猜的替代方案是组合,其中我有一个标准元素,其中可以包含一个至少是某物"的子元素..
I'm sure this is possible, the alternative I guess is composition, where I have a standard element that can contain a single child that is at least a 'Something'..
提前致谢,xsd 不是我的强项.
Thanks in advance, xsd isn't my strong point.
编辑,好吧,到目前为止我发现的最接近的东西基本上是:
Edit, ok the closest thing I've found so far is basically:
<somethings>
<something xsi:type="something-something" a="foo" b="0" />
<something xsi:type="another-something" a="bar" b="1" />
<something xsi:type="example:anything-something" a="baz" b="2" />
</somethings>
我想这是唯一的处理方式吗?如果是这样的话,这还不算太糟糕,而且 vs 智能感知似乎已经足够了解这一点了.
I guess this is the only way this is handled? if so this isn't so bad, and vs intellisense seems to understand this well enough.
谢谢.
推荐答案
这是个好问题.您可以执行一系列any",这将允许您在内部任意命名元素 - 但这不会以任何方式限制它们.或者,下面的架构限制了名称和属性,但没有其他限制(如您的第二个示例)
This is a good question. You could do a sequence of "any", which would allow you have arbitrarily named elements inside - but that won't constrain them in any way. Alternately, the schema below constrains the name and the attributes, but nothing else (as in your second example)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="somethingsType" >
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="a" type="xs:string"/>
<xs:attribute name="b" type="xs:string"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="somethingsSeq" >
<xs:sequence>
<xs:element name="something" type="somethingsType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="somethings" type="somethingsSeq"/>
</xs:schema>
我找不到限制类型而不是元素名称的方法.
I can't find a way to constrain the type but not the element name.
这篇关于作为特定复杂类型的扩展的任何类型元素的 xsd 序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!