The xsd sequence of any element type that is an extension of a particular complex type

Basically, if it 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 as they want to be, as long as their complex type is an extension of the complex type that I define.

So it might look something like this:

 <somethings> <something-something a="foo" b="0" /> <another-something a="bar" b="1" /> <example:anything-something a="baz" b="2" /> </somethings> 

I am sure that this is possible, an alternative, I think, is a composition where I have a standard element that can contain one child, which at least is β€œsomething”.

Thanks in advance, xsd is not my forte.


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 think this is the only way to handle this? if so, then this is not so bad, and against intellisense, it seems to understand this well.

Thanks.

+4
source share
1 answer

That's a good question. You can make the sequence "any" that allows you to arbitrarily name elements inside - but this will in no way limit them. Alternatively, the diagram below restricts the name and 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 cannot find a way to restrict the type, but not the name of the element.

+1
source

All Articles