Take the XSD W3C as an example:
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cars.example.com/schema" xmlns:target="http://cars.example.com/schema"> <complexType name="Vehicle" abstract="true"/> <complexType name="Car"> <complexContent> <extension base="target:Vehicle"/> ... </complexContent> </complexType> <complexType name="Plane"> <complexContent> <extension base="target:Vehicle"/> <sequence> <element name="wingspan" type="integer"/> </sequence> </complexContent> </complexType> </schema>
and the following definition "means OfTravel":
<complexType name="MeansOfTravel"> <complexContent> <sequence> <element name="transport" type="target:Vehicle"/> </sequence> </complexContent> </complexType> <element name="meansOfTravel" type="target:MeansOfTravel"/>
With this definition, you need to specify the type of your instance using xsi: type, for example:
<meansOfTravel> <transport xsi:type="Plane"> <wingspan>3</wingspan> </transport> </meansOfTravel>
I just would like to get the name "type name" - "element name" so that it can be replaced simply
<meansOfTravel> <plane> <wingspan>3</wingspan> </plane> </meansOfTravel>
The only way to do this so far is to make it explicit:
<complexType name="MeansOfTravel"> <sequence> <choice> <element name="plane" type="target:Plane"/> <element name="car" type="target:Car"/> </choice> </sequence> </complexType> <element name="meansOfTravel" type="target:MeansOfTravel"/>
But that means that I have to list all the possible subtypes in the complex "MeansOfTravel" type. Isn't there a way to force the XML parser to assume that you mean βplaneβ if you call the βplaneβ of an element? Or do I need to make the choice explicit? I just wanted to keep my DRY design - if you have other suggestions (like groups or so) - I'm all ears.
source share