What are all the scenarios in which targetNamespace can be added to attribute declarations?

Hi Folks,

Below I show an example of an attribute declaration with a targetNamespace attribute.

The attribute is embedded inside a complexType that restricts another complexType that is in a different namespace.

Is my example illustrative of the only scenario in which the targetNamespace attribute can be added to an attribute declaration? Or are there other scenarios?

/Roger


--------------------------------------------------------------------------------
              BookStore.xsd
--------------------------------------------------------------------------------
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                   targetNamespace="http://www.bookstore.org"
                   xmlns="http://www.bookstore.org"
                   xmlns:b="http://www.book.org"
                   elementFormDefault="qualified">

    <xs:import namespace="http://www.book.org"
                      schemaLocation="Book.xsd"/>

    <xs:complexType name="BookTypeMyNamespace">
        <xs:complexContent>
            <xs:restriction base="b:BookType">
                <xs:sequence>
                    <xs:element name="Title" type="xs:string" targetNamespace="http://www.book.org"/>
                    <xs:element name="Author" type="xs:string" maxOccurs="2" targetNamespace="http://www.book.org"/>
                    <xs:element name="Date" type="xs:gYear" targetNamespace="http://www.book.org"/>
                    <xs:element name="ISBN" type="xs:string" targetNamespace="http://www.book.org"/>
                    <xs:element name="Publisher" type="xs:string" targetNamespace="http://www.book.org"/>
                </xs:sequence>
                <xs:attribute name="id" type="xs:ID" use="required" targetNamespace="http://www.book.org"/>  <!--  HERE IT IS -->
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:element name="BookStore">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Book" maxOccurs="unbounded" type="BookTypeMyNamespace" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

--------------------------------------------------------------------------------
              Book.xsd
-------------------------------------------------------------------------------
-<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                   targetNamespace="http://www.book.org"
                   xmlns="http://www.book.org"
                   elementFormDefault="qualified">

        <xs:complexType name="BookType">
            <xs:sequence>
                <xs:element name="Title" type="xs:string"/>
                <xs:element name="Author" type="xs:string" maxOccurs="unbounded"/>
                <xs:element name="Date" type="xs:gYear"/>
                <xs:element name="ISBN" type="xs:string"/>
                <xs:element name="Publisher" type="xs:string"/>
            </xs:sequence>
            <xs:attribute ref="id" />
        </xs:complexType>
    
        <xs:attribute name="id" type="xs:ID" />

</xs:schema>

Received on Tuesday, 31 July 2012 20:09:09 UTC