views:

209

answers:

1

Is there a way to create an XSD that allows an attribute from a different namespace, but only if it's qualified? An example of an XML file that would 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"/&gt;

The schema should enforce the size attribute to be qualified and that is the part that I can't get to work.

A: 

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

Now you will have defined a namespace prefix to another definition that is known to your schema. You can now use elements of that other definition in your instance document prefixed with the namespace prefix you defined in your schema. This works best if the other definition document is also a schema.

Thanks, I managed to solve it by importing the document-extensions schema from the document schema and then referencing an attribute group.I didn't use the attributeFormDefault="qualified", since I wanted to be able to mix unqualified attributes with qualified ones.
levi_h