Defining an alias for XML element in XSD Schema

你。 提交于 2019-12-10 15:12:08

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/12460560/defining-an-alias-for-xml-element-in-xsd-schema

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!