Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > My schema validation is not working?

Reply
Thread Tools

My schema validation is not working?

 
 
wooks
Guest
Posts: n/a
 
      07-28-2003
<?xml version='1.0'?>
<userlogin xmlns="urn:faster:userlogin"
xmlnssi='http://www.w3.org/2001/XMLSchema-instance'>
<login>mick</login>
<password>brown</password>
</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"
xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlns="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:all>
<xsd:element name='login' type='login' />
<xsd:element name='password' type='password' />
</xsd:all>
</xsd:complexType>
<xsd:element name="userlogin" type="userloginType" />
</xsd:schema>


Here are the 2 included schemas

<?xml version="1.0"?>
<xsd:schema xmlnssd="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"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>




<?xml version="1.0"?>
<xsd:schema xmlnssd="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:restriction>
</xsd:simpleType>
</xsd:schema>

The schema always seems to flag an error on the login field regardless
of the validation rules.

Can anyone help?
 
Reply With Quote
 
 
 
 
C. M. Sperberg-McQueen
Guest
Posts: n/a
 
      07-29-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (wooks) writes:

> <?xml version='1.0'?>
> <userlogin xmlns="urn:faster:userlogin"
> xmlnssi='http://www.w3.org/2001/XMLSchema-instance'>
> <login>mick</login>
> <password>brown</password>
> </userlogin>
>
>
> Above is my schema instance.
>
> Here is my schema as you can see it does 2 includes .

....
> <xsd:element name='login' type='login' />

....
> <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"/>
> </xsd:restriction>
> </xsd:simpleType>

....
> The schema always seems to flag an error on the login field regardless
> of the validation rules.


Well, the definition of the simple type 'login', used by
the 'login' element, does say the only three legal values
are 'tom', 'dick', and 'harry'. And the document instance
does have the value 'mick'. So the document instance does
seem to contain an error.

It looks to me as if the validator is only Doing What You Said.

If you want any NCName containing at least three characters to
be a legal login, then lose the enumerations (and make the
corresponding change to the password type, too). The
values 'tom', 'dick', and 'harry' will all still be legal.

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium
 
Reply With Quote
 
 
 
 
wooks
Guest
Posts: n/a
 
      07-31-2003
<wooks>Below was sent to me by email. I had figured out some of it by
reading http://www.xfront.com/ZeroOneOrManyNamespaces.pdf but the post
comprehensively adresses my lingering confusions (I understood the fix
but didn't understand why it worked. I definitely will start using XSV
as a diagnostic tool instead of relying solely on MSXML</wooks>


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:

file:///D:/schema/exx/wooks/di2.xml:4:4:
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}assword]

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

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"
xmlnssi='http://www.w3.org/2001/XMLSchema-instance'>
<login>mick</login>
<password>brown</password>
</ul:userlogin>

or

<?xml version='1.0'?>
<userlogin xmlns="urn:faster:userlogin"
xmlnssi='http://www.w3.org/2001/XMLSchema-instance'>
<login xmlns="">mick</login>
<password xmlns="">brown</password>
</userlogin>

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

<xsd:schema targetNamespace="urn:faster:userlogin"
xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:faster:userlogin"
elementFormDefault="qualified"
>

...
</xsl:schema>

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

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

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.

<wooks>understatement of the year )</wooks>

-C. M. Sperberg-McQueen
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New to xml schema - does the dtd/schema validation happens always ? pramodr XML 3 04-05-2009 12:10 PM
Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema huntingseasonson@gmail.com Perl Misc 5 11-29-2006 12:37 PM
Problem with schema-validation and property "http://apache.org/xml/properties/schema/external-schemaLocation" Markus Java 1 11-23-2005 02:41 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
Complex validation of business rules possible with XML Schema? Any other validation "languages"? Mike XML 1 11-21-2003 07:27 PM



Advertisments