473,602 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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" elementFormDefa ult="qualified" >
<xs:element name="books">
<xs:complexType >
<xs:sequence>
<xs:element name="book" minOccurs="0"
maxOccurs="unbo unded">
<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:schemaLocat ion="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="Paradise t" 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 9918
On Feb 21, 8:22 pm, "Eric Lilja" <mindcoo...@gma il.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...@gma il.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 "technologi es"
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 "prescripti ve, 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
2928
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 I parse some element from XML document I don't know until runtime the type of the element (it depends on the type used in user-defined schema). XML parser obviously validates that the value of the element is correct type but still I receive that...
2
1536
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 against a schema. The following document validates ok at http://www.stg.brown.edu/service/xmlvalid/ which doesn't check the schema. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
8
1829
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 name="next" type="Llist"/> </xsd:sequence> </xsd:complexType>
0
1491
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" encoding="UTF-8"?> <virtuose xmlns="http://www.virtuose.it/ns/virtuose" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.virtuose.it/ns/virtuose F:\Tesi\virtuose_1.1.xsd">
0
3265
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 Ref_to_A. Both are allowed to be instantiated under the root element by declaring an element of the base class. I want to have type safety for the reference by using key/keyref.
4
2494
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 of projects. Therefore, I wish to include the project customType in the projectCollection namespace. I therefore have declared two xsd documents: project.xsd and projectcollection.xsd
3
1859
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 schema validates fine in XMLSpy and in VS2005. However, in Visual Studio 2005 beta2, when i attempt to reference this schema from "Templates and Add-ins" it complains that "One or more of
5
1328
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 with the following tags: <type id="id1"/> <type id="id2"/> <type id="id3"/>
1
2160
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 the xml and validates correctly. When I try to use one of the enumeration in the drop down list, the xml will not validate. When I validate the xml in xmlspy, i get the error message "IDREF 'endofprogam': referenced ID 'endofprogam' was not found."...
3
3836
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" /> </xs:restriction> </xs:simpleContent>
0
7993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.