Writing an XML schema that allows qualified attributes from other namespaces to be used

Is there a way to create an XSD that allows an attribute from a different namespace, but only if it is qualified? An example XML file that will be valid according to the schema is -

<d:document dx:size="a5"
    xmlns:d="http://example.com/documents"
    xmlns:dx="http://example.com/document-extensions"/>

      

The schema needs to apply an attribute size

that needs to be qualified, and this is the part I can't work with.

+2


source to share


1 answer


In your open schema tag of your schema, not in the instance document, use attirbuteFormDefault = "qualified" to ensure that all attributes are namespace qualified. In your schema, you will need to import, not include, where this attribute is defined, and then assign a namespace prefix to the document you are importing.



You will now define a namespace prefix for a different definition that your schema knows. You can now use the elements of this different definition in your instance document with the namespace prefix defined in your schema. This works best if the other definition document is also a schema.

0


source







All Articles