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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Costello, Roger L.
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>

Reply | Threaded
Open this post in threaded view
|

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

Michael Kay

Yes, this is the use case that the targetNamespace attribute was
introduced for, and the WG decided to restrict its use to this scenario.
My own instinct was to generalize it so it could be used anywhere, but
the WG was reluctant to do this, as it would have meant a total
decoupling of the current relationship between schema documents and
namespaces.

Michael Kay
Saxonica

On 31/07/2012 21:08, Costello, Roger L. wrote:

> 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>
>
>