I have an attributeGroup with long list of allowed attributes say a:attr-group, that I import to another xsd to restrict an element's (defined in another xsd) allowed attributes with.
I also want to allow the same element to use the same attributes under a second namespace say b:attr-group, and wish to use the same file (rather than repeat all the attributes and group definition).
Is there a simple way of doing this? All my attempts so far have been thwarted by the import namespace must equal targetNamespace rule.
Thanks in advance!
This pattern is also known as chameleon. It means you're including an XML Schema that has no target namespace, which in turn makes that schema assume the namespace of the parent schema.
UPDATE: considering the sample XML provided in the comments:
First schema file (AttrGroup.xsxd):
Second schema file (A.xsd):
Third schema file (B.xsd):
Fourth XML Schema (Element.xsd):
Sample of valid XML:
Sample of invalid XML:
When validating against Element.xsd the invalid sample, I am getting this error message (on my tool): Error occurred while loading [], line 1 position 116 The 'http://tempuri.org/XMLSchema.xsd/b:attr2' attribute is invalid - The value '10a' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:int' - The string '10a' is not a valid Int32 value. D:...\SampleAttrGroup.xml is invalid.