Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema - How can I change the name of a ref'ed element?

Tags:

xml

schema

xsd

I'm an XML Schema noob, and this is my first Stack Overflow question. Please forgive my ignorance of standards and etiquette in both.

In an XML Schema file (.xsd), I'm including another schema (outside of my control) that represents a sort of de facto standard my group is using. Within the external schema is a complex element with a long name:

<xs:element name="AnnoyingLongElementNameOfSuffering">
    <xs:complexType>
        <xs:sequence>
            ...sub-elements galore...
        </xs:sequence>
    </xs:complexType>
</xs:element>

In my schema file, the element in question was copied, which I consider bad practice, and it was given an abbreviated, tiny name. What I'm trying to do is replace the copied code with a reference to the original in the other schema, but I need to maintain the tiny name, which is already used in existing instance files (also outside of my control). I'd like to do something like:

<xsd:element name="TinyName" ref="AnnoyingLongElementNameOfSuffering"/>

However, the 'name' and 'ref' attributes are mutually exclusive. I can't re-define it and re-list the sub elements, because they're not declared globally in the other schema. I can't make a derived type, because it's defined as an element in the other schema not a type. Alas, none of my searches have yielded anything helpful, presumably because you'd normally change the element name or modify the other file, neither of which is an option for me. There's probably a simple answer, so I look forward to your enlightening responses.

like image 519
Vitamin Smooth Avatar asked May 10 '11 19:05

Vitamin Smooth


1 Answers

Try:

<xsd:element name="TinyName" substitutionGroup="AnnoyingLongElementNameOfSuffering"/>

Also, tell the people who are maintaining the standard to stop using anonymous complex types (define inline within elements). There is a reason why most big standards use an approach based on defining types rather than elements: so that you can derive from the types or reuse them. Your internal standard could easily migrate to this without losing compatibility: keep the elements, but assign them explicit types.

like image 176
xcut Avatar answered Sep 27 '22 18:09

xcut