473,499 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xerces-c schema validation

Hello,

I've appended a simple XML file and it's appropriate schema below.
I want to validate the XML file against the schema with xerces-c.

This example contains a section where colours are defined and a section
where referenzes to these definitions are made.
Values are valid only if they were defined above.

A key constraint is defined for Definition/Color/ids, keyref to
Data/Item/color.

If I use an undefined color value, the parser gives me this error message:
Error at file data.xml, line 18, char 12
"The key for identity constraint of element 'DemoFile' is not found."

This is not very helpful to find the actual errornous line, because this
line number is at the end of the file.

Is there a way to get more accurate information about which line is wrong?
Or is it impossible due to the way xerces deals with key and keyref
constraints (only in the scope of the element)?

best regards,
Harald.

---------8<--------- data.xml -------------------

<?xml version="1.0"?>
<DemoFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema.xsd">
<Definition>
<Color id="red"/>
<Color id="green"/>
<Color id="blue"/>
</Definition>

<Data>
<Item color="red"></Item>
<Item color="green"></Item>
<Item color="blue"></Item>
<Item color="green"></Item>
<Item color="red"></Item>
</Data>

</DemoFile>

---------8<-------end of data.xml ---------------
---------8<--------- schema.xsd -----------------
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="DemoFile">
<xs:complexType>
<xs:sequence>
<xs:element name="Definition">
<xs:complexType>
<xs:sequence>
<xs:element name="Color" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="Data">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="color" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="TypeId">
<xs:selector xpath="Definition/Color"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="IdExists" refer="TypeId">
<xs:selector xpath="Data/Item"/>
<xs:field xpath="@color"/>
</xs:keyref>
</xs:element>
</xs:schema>
---------8<-------end of schema.xsd ---------------
Sep 1 '05 #1
5 1941
XSV is happy with your instance. . .

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
Sep 2 '05 #2
Henry S. Thompson wrote:
XSV is happy with your instance. . .


The schema is correct, but I would like the parser to be more precisely in
indicating an error in the XML-File.

When inserting an item in the Data-section which has no reference value in
the above section:
<Item color="yellow"></Item>

Xerces points me to the end of the root-element[1]. Isn't it possible to
find out that the errornous element is at line 14?
best regards,
Harald.
[1]: Error message of xerces:
line 20, char 12
The key for identity constraint of element 'DemoFile' is not found.
Sep 2 '05 #3
Harald Haspl writes:
Henry S. Thompson wrote:
XSV is happy with your instance. . .


The schema is correct, but I would like the parser to be more precisely in
indicating an error in the XML-File.

When inserting an item in the Data-section which has no reference value in
the above section:
<Item color="yellow"></Item>

Xerces points me to the end of the root-element[1]. Isn't it possible to
find out that the errornous element is at line 14?


XSV does give the error message you want [1], but note that Xerces is not
being unreasonable, the error isn't detected untell then end of the
scope of the keyref.

ht

[1]
<invalid char="9" code="cvc-identity-constraint.2.3.2" line="13"
resource="file:///.../data1.xml">no key in {None}:TypeId
for yellow</invalid>
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
Sep 5 '05 #4
On 2005-09-05, Henry S. Thompson <ht@inf.ed.ac.uk> wrote:
Harald Haspl writes:
Isn't it possible to find out that the errornous element is at line 14?

XSV does give the error message you want [1], but note that Xerces is not
being unreasonable, the error isn't detected untell then end of the
scope of the keyref.


Thanks for your reply, finally I found what I need:
If parsing of an XML file fails, I can check it with xmllint afterwards
and get more detailed indication where the error is located.

greetings,
Harald.

Sep 8 '05 #5
earlati
1 New Member
I'm interesting to this topic, also because I get the same problem[1], that's to say the XercesDOMParser didn't show the right place where error is located.

Henry, how do you get the right error info [2] ?

[1]: Error message of xerces:
line 20, char 12
The key for identity constraint of element 'DemoFile' is not found.

[2]: <invalid char="9" code="cvc-identity-constraint.2.3.2" line="13"
resource="file:///.../data1.xml">no key in {None}:TypeId
for yellow</invalid>
Sep 21 '05 #6

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

Similar topics

0
4240
by: bugbear | last post by:
Subject pretty much says it all. I'd like to parse XML (duh!) using Xerces (because its fast, and reliable, and comprehensive, and supports lots of features). I'd like to conform to standards...
2
2707
by: Bekkali Hicham | last post by:
hi, i have downloaded the latest version 2.4 of Xerces, and unziped it, i end up with a diectory hierarchy like this c:\xerces-2_4_0\XercesImpl.jar c:\xerces-2_4_0\XercesSamples.jar...
1
11215
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading...
0
3067
by: Waseem | last post by:
Hi I have looked and tried everything and i still cant sort this out i have no idea why this wont work I am using Xerces Perl on Windows and Debian to try this and it wont work on both of...
0
1829
by: Jim Phelps | last post by:
After having memory leak issues with Xerces-c 2.3.0 for Solaris 2.7 for CC 6.2 I have decided to update to at least 2.4. I have downloaded the binary tarball and have installed it on my...
0
1805
by: Dale Gerdemann | last post by:
I've been trying to use DOM level 3 with xerces-2_6_2. There's a sample called samples/DOM3.java, but I've had trouble with compilation. I've downloaded Xerces-J-bin.2.6.2 and...
18
7702
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
3
3375
by: Matt | last post by:
Hello, Summary: Where can one download a Xerces-C (XML pardser) dynamic library file (.DLL file) for Windows (Win98/WinNT/Win2k/WinXP/Win2003, including server flavors; don't need to support...
2
3394
by: Vlad Zorinov | last post by:
I'm getting the following error after a couple of months of XML processing, using Xerces 2.0.0 in an apache tomcat. Does anyone have any ideas what this problem may be or what I should do to solve...
3
1915
by: Raphael Tagliani | last post by:
(english version below) Bonjour! Je travaille sur un gros projet java, qui parse beaucoup de fichiers xml au lancement d'un serveur. Nous avons un problème de concurrence qu lancement. En...
0
7130
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,...
0
7171
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,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
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...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.