Defining an alias for XML element in XSD Schema

2019-06-23 07:39发布

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" />

标签: xml xsd alias
1条回答
狗以群分
2楼-- · 2019-06-23 08:34

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">...
查看更多
登录 后发表回答