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

T

Thomas Marti

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

Jesper Zedlitz

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top