Require an attribute from a different namespace in an XSD schema

278 Views Asked by At

I have an XSD file describing a schema.

The root element in the schema requires an attribute that is defined in another xsd (that I have the url for). Specifically, I want the root element of a document to require the attribute:

xsi:noNamespaceSchemaLocation="schema/SomeSchema.xs"

where

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

How do I describe this in the documents xsd?

1

There are 1 best solutions below

0
On BEST ANSWER

xsd.exe is based on XSD 1.0 spec; that spec doesn't work with references to xsi:attributes.

However, this should work with an XSD 1.1 processor:

<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com)-->
<xsd:schema xmlns="urn:tempuri-org:XSD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:tempuri-org:XSD" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="root">
        <xsd:complexType>
            <xsd:simpleContent>
                <xsd:extension base="xsd:string">
                    <xsd:attribute ref="xsi:noNamespaceSchemaLocation" use="required"/>
                </xsd:extension>
            </xsd:simpleContent>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

The reason why you can't make it work with attributes from the XSI namespace in XSD 1.0 is because they are "special". XSD 1.1 relaxed some of that.