473,287 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

My schema validation is not working?

<?xml version='1.0'?>
<userlogin xmlns="urn:faster:userlogin"
xmlns:xsi='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"
xmlns:xsd="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 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"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>


<?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: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?
Jul 20 '05 #1
2 3289
wo****@hotmail.com (wooks) writes:
<?xml version='1.0'?>
<userlogin xmlns="urn:faster:userlogin"
xmlns:xsi='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
Jul 20 '05 #2
<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}: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"
xmlns:xsi='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"
xmlns:xsi='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"
xmlns:xsd="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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > ...
6
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. ...
4
by: joes | last post by:
Hello there I tried for several days to get a simple validation with xml schema & xerces working. Goal for me is tuse JAXP and not specific Xerces classes. I don't get the point what I am doing...
3
by: william_hulse | last post by:
The general process i am currently working on is this: STEP 1 xml doc1 is transformed using stylesheet1 to produce xml doc2 - xml doc1 has a namespace declaration as follows... <?xml...
2
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data....
4
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set...
1
by: Dan Bass | last post by:
There's an XML message I have, that has no namespace information. Then there is a XSD schema that is must validate against, but this has a targetNamespace and xmlns of...
1
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i...
0
by: Mark Parter | last post by:
I'm trying convert an XML Schema (http://www.elframework.org/projects/xcri/efc_r1.0.xsd/view) to a VB.Net class using the XSD tool provided with the .NET 2 SDK. However, it's failing to generate...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.