473,320 Members | 2,027 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,320 software developers and data experts.

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

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 xmlns:xs="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" xmlns:xsi="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

Feb 21 '07 #1
3 9886
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

Feb 21 '07 #2
On 21 Feb, 19:46, "roy axenov" <r_axe...@mail.ruwrote:
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

Feb 21 '07 #3
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.
Feb 21 '07 #4

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

Similar topics

4
by: Jari Kujansuu | last post by:
I can successfully parse XML document using SAX or DOM and I can also validate XML document against schema. Problem is that my program should deal with user-defined schemas which means that when...
2
by: Miel Bronneberg | last post by:
Hi, I've got a problem validating an xml document with both a dtd and a schema. The problem seems to be about namespaces. What I want is a well-formed, valid XML document, which also validates...
8
by: Jakob Møbjerg Nielsen | last post by:
Hi Is it possible to represent a linked list in XML-Schema. Somthing like: <xsd:complexType name="Llist" > <xsd:sequence> <xsd:element name="content" type="xsd:string"/> <xsd:element...
0
by: chobin | last post by:
Hi all. I've a terrible question. I've to build one XML page (based on a xml schema) that implements a dynamic database. In particular, I would declare something like this: <?xml version="1.0"...
0
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have two complex (A and B) types which both inherit from a common base typ (Base). A refers B using a xs:IDREF element named...
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...
3
by: farseer | last post by:
Hello, i have a schema which also imports the XHTML schema: <xsd:import namespace="http://www.w3.org/1999/xhtml" schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"/> This...
5
by: Lemon Tree | last post by:
Hello everybody. I have a problem with Schema Definitions and I cannot figure out how to solve it (provided that it could be solved :)) Here we go... Let's suppose to have a simple XML file...
1
by: stran | last post by:
I'm trying to create a simple type that holds two different types. The first is IDREF and the second is an enumeration of string. When I generate a sample xml, I can enter any ID previously stated in...
3
by: Kai Schlamp | last post by:
Hello! In my schema I have the following: <xs:complexType name="textareaType"> <xs:simpleContent> <xs:restriction base="xs:string"> <xs:attribute ref="label" use="required" />...
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: 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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.