XML-Schema, which only declares an Attribute and no elements?

Discussion in 'XML' started by Thomas Marti, Nov 24, 2003.

  1. Thomas Marti

    Thomas Marti Guest

    Hello

    I have the following problem: I want to have an XML-Schema that only
    declares one Attribute, but does not specify in which specific Element it
    has to be used. I've already tried the following:

    ------- agnes.xsd --------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schematargetNamespace="http://agnes.sf.net/ns/agnes"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" xmlns="http://agnes.sf.net/ns/agnes">
    <xsd:complexType name="agnesType">
    <xsd:attribute name="id" type="idType"/>
    </xsd:complexType>
    <xsd:simpleType name="idType">
    <xsd:restriction base="xsd:token">
    <xsd:pattern value="AGID_[0-9a-zA-Z]{16}"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:schema>
    ------- agnes.xsd --------------------------------------------------


    The intented use of this Schema would be:

    ------- whatever.xsd -----------------------------------------------
    <whatever xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:agnes="http://agnes.sf.net/ns/agnes"
    xsi:schemaLocation="http://agnes.sf.net/ns/agnes agnes.xsd"
    agnes:id="AGID_1234567890abcdef">
    <foo>
    <bar/>
    </foo>
    </whatever>
    ------- whatever.xsd -----------------------------------------------

    But XMLSpy outputs the following error:
    'No Content Model available for validation (possibly empty DTD/Schema)'

    => So the question is: How can I declare an Attribute in it's own Schema so
    that it can be used in different kinds of elements?


    --
    Bye, Thomas

    'No Intensity, no Victory'
    Any Given Sunday, 1999
    Thomas Marti, Nov 24, 2003
    #1
    1. Advertising

  2. > I have the following problem: I want to have an XML-Schema that only
    > declares one Attribute, but does not specify in which specific Element it
    > has to be used. I've already tried the following:
    >
    > ------- agnes.xsd --------------------------------------------------
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsd:schematargetNamespace="http://agnes.sf.net/ns/agnes"
    > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > elementFormDefault="qualified" xmlns="http://agnes.sf.net/ns/agnes">
    > <xsd:complexType name="agnesType">
    > <xsd:attribute name="id" type="idType"/>
    > </xsd:complexType>
    > <xsd:simpleType name="idType">
    > <xsd:restriction base="xsd:token">
    > <xsd:pattern value="AGID_[0-9a-zA-Z]{16}"/>
    > </xsd:restriction>
    > </xsd:simpleType>
    > </xsd:schema>
    > ------- agnes.xsd --------------------------------------------------
    >

    You do not need the complexType named "agnesType". Instead use a reference
    to the attribute "id".

    In the schema for your 'real' data import agnes.xsd:
    <xsd:import schemaLocation="agnes.xsd"
    namespace="http://agnes.sf.net/ns/agnes"/>

    You can use a reference to an attribute from that schema, i.e.
    <xsd:element name="whatever">
    <xsd:complexType>
    <xsd:sequence> ... </xsd:sequence>
    <xsd:attribute ref="agnes:id"
    xmlns:agnes="http://agnes.sf.net/ns/agnes"/>
    </xsd:complexType
    </xsd:element>

    > But XMLSpy outputs the following error:
    >

    I do not know if XMLSpy can understand the construction above since its
    capabilities are quite limited when it comes to more complex schemas.

    Jesper

    --
    Jesper Zedlitz eMail :
    Homepage : http://www.zedlitz.de
    ICQ# : 23890711
    PGP-Key : http://zedlitz.de/pub_key.asc
    Jesper Zedlitz, Nov 25, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page