开发者

xsd sequence of any type of element that is an extension of specific complex type

开发者 https://www.devze.com 2022-12-15 17:41 出处:网络
Basically if this was .NET, it would look like this: ISomething { string A { get; } int B { get; } } var somethings = new List<ISomething>();

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.

So it may look something like:

<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'..

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>

I guess this is the only wa开发者_开发知识库y this is handled? if so this isn't so bad, and vs intellisense seems to understand this well enough.

Thanks.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号