Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining an alias for XML element in XSD Schema

Tags:

alias

xml

xsd

Is there XSD language support or tricks (e.g. via the preprocessor) for defining an alias for an XML element? I would like to alias all the elements in my schema in order to create an option for a more cryptic but network bandwidth-efficient version of our XML documents.

For example, I would like to define a name such as IRQ to be an alias for the element InterruptRequest etc.

<xs:element name="InterruptRequest" minOccurs="0">
    <xs:complexType>
        <xs:attribute name="level" type="xs:unsignedShort" use="required"/>
    </xs:complexType>
</xs:element>

So that the following two declarations are equivalent to each other

<!-- Human readable but bandwidth inefficient -->
<InterruptRequest level="22" /> 

<!-- Cryptic, but comparatively bandwidth efficient -->
<IRQ level="22" />
like image 448
Olumide Avatar asked Sep 17 '12 13:09

Olumide


1 Answers

You can't define two element names to be synonymous, but you can define one as substitutable for the other by means of a substitution group. They will still appear differently to your application, but the validation process will permit one of them to be used everywhere that the content model permits the other.

<element name="a">...

<element name="b" substitutionGroup="a">...
like image 167
Michael Kay Avatar answered Oct 07 '22 07:10

Michael Kay