Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Schema with ID/IDREF validates, but xml-file that uses it does not

Reply
Thread Tools

Schema with ID/IDREF validates, but xml-file that uses it does not

 
 
Eric Lilja
Guest
Posts: n/a
 
      02-21-2007
Sorry for asking so many questions, but I've just started and need to
get some things working so I can do the task that is before me.

Consider this (validating) schema:
<?xml version="1.0"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
targetNamespace="myns" xmlns="myns" elementFormDefault="qualified">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="author" minOccurs="1"
maxOccurs="1">
<xs:complexType>
<xs:attribute name="id" type="xs:ID"
use="required"/>
<xs:attribute name="name" type="xs:string"
use="required"/>
</xs:complexType> <!-- authors complexType -->
</xs:element> <!-- author -->
</xs:sequence> <!-- book sequence -->
<xs:attribute name="title" type="xs:string"
use="required"/>
<xs:attribute name="isbn" type="xs:string"
use="required"/>
<xs:attribute name="author-id" type="xs:IDREF"
use="required"/>
</xs:complexType> <!-- book complexType -->
</xs:element> <!-- book -->
</xs:sequence> <!-- books sequence -->
</xs:complexType> <!-- books complexType -->
</xs:element> <!-- books -->
</xs:schema>

I try to use it with the following xml-file:
<?xml version="1.0" encoding="utf-8"?>
<books xmlns="myns" xmlnssi="http://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocation="myns books-with-id_idref.xsd">
<book title="Winter's Heart" isbn="123456789" author-id="4711">
<author id="4711" name="Robert Jordan"/>
</book>
<book title="Paradiset" isbn="987654321" author-id="1337">
<author id="1337" name="Liza Marklund"/>
</book>
</books>

But I get these errors:
Location: 3:66
Description: cvc-datatype-valid.1.2.1: '4711' is not a valid value for
'NCName'.

Location: 3:59
Description: cvc-attribute.3: The value '4711' of attribute 'author-
id' on element 'book' is not valid with respect to its type, 'IDREF'.

Location: 4:45
Description: cvc-datatype-valid.1.2.1: '4711' is not a valid value for
'NCName'.

Location: 4:16
Description: cvc-attribute.3: The value '4711' of attribute 'id' on
element 'author' is not valid with respect to its type, 'ID'.

Location: 6:61
Description: cvc-datatype-valid.1.2.1: '1337' is not a valid value for
'NCName'.

Location: 6:54
Description: cvc-attribute.3: The value '1337' of attribute 'author-
id' on element 'book' is not valid with respect to its type, 'IDREF'.

Location: 7:45
Description: cvc-datatype-valid.1.2.1: '1337' is not a valid value for
'NCName'.

Location: 7:16
Description: cvc-attribute.3: The value '1337' of attribute 'id' on
element 'author' is not valid with respect to its type, 'ID'.

I've clearly not understood this..what am I doing wrong and what need
I do to get it working?

Thanks for any replies!

- Eric

 
Reply With Quote
 
 
 
 
roy axenov
Guest
Posts: n/a
 
      02-21-2007
On Feb 21, 8:22 pm, "Eric Lilja" <mindcoo...@gmail.com>
wrote:
> Sorry for asking so many questions, but I've just started
> and need to get some things working so I can do the task
> that is before me.


Read a book. You're not going to learn much if you just ask
lots of questions and make no effort to learn on your own.

http://www.w3.org/TR/xmlschema-0/

....is a good enough starting point for learning about XML
Schemata.

> Location: 3:66
> Description: cvc-datatype-valid.1.2.1: '4711' is not a
> valid value for 'NCName'.


It tells you precisely what is wrong with your document.
You declared this attribute as xs:IDREF. '4711' is not a
valid xs:IDREF value. Finding out why should be trivial
for anyone with intelligence quotient higher than their
shoe size.

XML Schema Recommendations are published by W3C. On their
website you should see an XML Schema section in the list of
available topics. Click there.

You need Specifications and Development sub-sections. Click
on it.

'XML Schema Part 2: Datatypes' looks like it might help
you. Click it.

Search for IDREF. Click on the link. The text says that
IDREF is the set of all string that match the NCName
production. Click on NCName.

[4] NCName ::= (Letter | '_') (NCNameChar)*

Here it goes... looks like IDREF's (and ID's) have to start
with a letter or an underscore. That's your immediate
problem, and the error message you received together with
good ole rubbing a couple of brain cells together should've
gotten you there in two minutes or so.

> I've clearly not understood this..what am I doing wrong
> and what need I do to get it working?


I think it would be harmful for you to simply tell you how
it's done. But I'll give you an awfully good hint: XML
Schema Part 0: Primer document I referred above contains
the information necessary for doing it right.

--
roy axenov

 
Reply With Quote
 
 
 
 
Eric Lilja
Guest
Posts: n/a
 
      02-21-2007
On 21 Feb, 19:46, "roy axenov" <r_axe...@mail.ru> wrote:
> On Feb 21, 8:22 pm, "Eric Lilja" <mindcoo...@gmail.com>
> wrote:
>
> > Sorry for asking so many questions, but I've just started
> > and need to get some things working so I can do the task
> > that is before me.

>
> Read a book. You're not going to learn much if you just ask
> lots of questions and make no effort to learn on your own.


I have the book Internet and the World Wide Web How to program, which,
briefly, discusses xml. I'm starting out with several "technologies"
related to web right now so that book seemed a good purchase. Since
the book is a bit light on XML I've been using the web alongside. XML
is one thing that I want to have more than a cursory knowledge of,
though, so I'm trying to decide on a good book. I was looking at
O'Reilly's selection and plan to visit the local campus library to do
some browsing and see which one I like. One of my upcoming projects is
changing my applications to use xml for storing user settings and
whatnot.

>
> http://www.w3.org/TR/xmlschema-0/
>
> ...is a good enough starting point for learning about XML
> Schemata.


This link keeps turning up when I google but, unfortunately, the
information is somewhat densely presented for me at the moment.

>
> > Location: 3:66
> > Description: cvc-datatype-valid.1.2.1: '4711' is not a
> > valid value for 'NCName'.

>
> It tells you precisely what is wrong with your document.
> You declared this attribute as xs:IDREF. '4711' is not a
> valid xs:IDREF value. Finding out why should be trivial
> for anyone with intelligence quotient higher than their
> shoe size.
>
> XML Schema Recommendations are published by W3C. On their
> website you should see an XML Schema section in the list of
> available topics. Click there.
>
> You need Specifications and Development sub-sections. Click
> on it.
>
> 'XML Schema Part 2: Datatypes' looks like it might help
> you. Click it.
>
> Search for IDREF. Click on the link. The text says that
> IDREF is the set of all string that match the NCName
> production. Click on NCName.
>
> [4] NCName ::= (Letter | '_') (NCNameChar)*
>
> Here it goes... looks like IDREF's (and ID's) have to start
> with a letter or an underscore. That's your immediate
> problem, and the error message you received together with
> good ole rubbing a couple of brain cells together should've
> gotten you there in two minutes or so.
>
> > I've clearly not understood this..what am I doing wrong
> > and what need I do to get it working?

>
> I think it would be harmful for you to simply tell you how
> it's done. But I'll give you an awfully good hint: XML
> Schema Part 0: Primer document I referred above contains
> the information necessary for doing it right.


A bit rudely put I think, but I guess that's easy on the internet. I
did search for it, though, but I didn't look closely enough and was
confused by an example that used integer literals as IDs. But, you're
right, I should have been able to find the proper definition myself.
Anyway, you solved my problem and for that I say thanks.

>
> --
> roy axenov


- Eric

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-21-2007
Reading W3C documents, even introductory ones, does assume a basic level
of experience which beginners may not have. They're written by experts,
for experts, so they tend to be terse; the official goal seems to be to
make them "prescriptive, not descriptive", and I actually got some
pushback when folks felt I was crossing that line. The assumption seems
to be that other people will take the W3C books and write tutorial
material based on them.

And, in fact, there are also many tutorials and introductory articles
available on the web.

I hope folks will forgive me for blowing the company trumpet again and
reminding everyone that many of those resources can be found at
http://www.ibm.com/xml
And in other places, of course.
 
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
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
New to xml schema - does the dtd/schema validation happens always ? pramodr XML 3 04-05-2009 12:10 PM
Axis2 Method call on autogenerated WSDL uses schema targetnamespace !?? Robsy Java 0 12-17-2006 02:35 PM
my table updates but the view that uses it does not Norm via DotNetMonster.com ASP .Net 2 05-23-2005 10:17 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



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57