470,815 Members | 1,187 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

qualified and unqualified local elements (was: My schema validation is not working?)

wooks (wo****@hotmail.com) wrote:
<?xml version='1.0'?>
<userlogin xmlns="urn:faster:userlogin"
</userlogin> Above is my schema instance.
Here is my schema as you can see it does 2 includes . <?xml version="1.0"?>
<xsd:schema targetNamespace="urn:faster:userlogin"
<xsd:include schemaLocation="C:\Faster\App\Demo\DataTypes\login .xsd"
<xsd:include schemaLocation="C:\Faster\App\Demo\DataTypes\passw ord.xsd"
<xsd:complexType name="userloginType">
<xsd:element name='login' type='login' />
<xsd:element name='password' type='password' />
<xsd:element name="userlogin" type="userloginType" />

Here are the 2 included schemas

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="login">
<xsd:restriction base="xsd:NCName">
<xsd:enumeration value="tom"/>
<xsd:enumeration value="dick"/>
<xsd:enumeration value="harry"/>
<xsd:minLength value="3"/>

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="password">
<xsd:restriction base="xsd:NCName">
<xsd:enumeration value="cruise"/>
<xsd:enumeration value="cheney"/>
<xsd:enumeration value="truman"/>
<xsd:minLength value="6"/>
</xsd:schema> The schema always seems to flag an error on the login field
regardless of the validation rules. Can anyone help?
I think the problem relates to the way the 'login' and 'password'
elements are declared. When I validate the example using these schema
documents, XSV gives me the following error message:

Invalid per cvc-complex-type.1.2.4:
element {urn:faster:userlogin}:login not allowed here (1)
in element {urn:faster:userlogin}:userlogin,
expecting [{None}:login,{None}:password]

As well as (later on):

file:///D:/schema/exx/wooks/di2.xml:4:4: Invalid per src-resolve:
undeclared element {urn:faster:userlogin}:login

file:///D:/schema/exx/wooks/di2.xml:5:4: Invalid per src-resolve:
undeclared element {urn:faster:userlogin}:password

From the first error message, we know that the schema processor is
expecting the 'login' and 'password' elements to be unqualified (to
be, as some people say, 'in the anonymous namespace'). We also know
that the 'login' and 'password' elements in the instance are in the
namespace urn:faster:userlogin -- both because the document instance
has a default namespace declaration for that namespace, and because
the schema processor tells us ("element {urn:faster:userlogin}:login
not allowed here", as well as the later error messages) that what it
found was indeed a 'login' element in namespace urn:faster:userlogin
-- for which it found no declaration.

The local elements are unqualified because the main schema document
shown above has (by default) elementFormDefault="unqualified", which
means that elements declared local to a complex type (here, 'login'
and 'password') are not namespace-qualified. Some schema authors
prefer this, reasoning by analogy with attributes with are local to an
element and which are similarly namespace-unqualified; other schema
authors prefer to set elementFormDefault="qualified" and associate all
the elements declared in a given schema document with the target
namespace given in the targetNamespace attribute of the schema
element. Each kind of schema author tends not only to be appalled at
the other kind's preference, but to be distressed to discover that
anyone on earth could be so perverse as to think namespaces should
work "that way". The XML Schema WG argued about this for a long time,
and eventually we all agreed to take our hands off each others'
throats and leave the decision to the schema author.

So there are two ways to make your document instance work:

(1) don't namespace-qualify the local elements in the instance. Make
your instance be

<?xml version='1.0'?>
<ul:userlogin xmlns:ul="urn:faster:userlogin"


<?xml version='1.0'?>
<userlogin xmlns="urn:faster:userlogin"
<login xmlns="">mick</login>
<password xmlns="">brown</password>

(2) do namespace-qualify the local elements in the schema. Make
the schema element read

<xsd:schema targetNamespace="urn:faster:userlogin"


You can also specify that the 'login' and 'password' elements
are namespace qualified without changing the default, thus:

<xsd:complexType name="userloginType">
<xsd:element name="login" type="login" form="qualified"/>
<xsd:element name='password' type='password' form="qualified"/>

although I don't recommend it, since having some local elements be
qualified and some be unqualified is a good recipe for confusion.

I hope this helps.

-C. M. Sperberg-McQueen
Jul 20 '05 #1
0 3977

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by axel_johard | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.