Is it possible to define in XML schema that there must be some certain XML attributes, and at the same time I want to allow to extend this list in future?
Here, if we have the following hypothetical part of XML declaration:
<xs:element name="MyTypeInstance" type="MyType" />
<xs:complexType name="MyType">
<xs:attribute name="FirstAttr" type="xs:int" use="required"/>
<xs:attribute name="SecondAttr" type="xs:string" use="required"/>
</xs:complexType>
Then the following XML document fragment is valid according to this schema:
<MyType firstAttr="123" secondAttr="abc" />
What I want is to be able to successfully validate the following XML fragment:
<MyType firstAttr="123" secondAttr="abc" ThirdAttr="some new value" />
The two main problems are:
- I don't want to change XML schema every time I need to introduce some new attribute because we don't want to force all of our client to update to the latest version of our software, and some of them don't update their apps for a long time;
- I can't just use
anyAttribute
in XML schema because I want to validate XML document before working with it. If I specify justanyAttribute
element, then I wouldn't know that some required attributes are missing. And as far as I understand XML doesn't allow to useattribute
andanyAttribute
elements in schema (at least I wasn't able to make such schema to work using .netXmlDocument
class).
It would be ideal if it would be possible to specify some attributes explicitly using attribute
element, so I would know exactly that these attributes are present in XML document, but at the same time I would let to extend XML document using anyAttribute
element.
How can it be done?