Re: [xml] Error report with RelaxNG
- From: Marc Poinot <Marc Poinot onera fr>
- To: xml gnome org
- Cc: Marc Poinot <Marc Poinot onera fr>
- Subject: Re: [xml] Error report with RelaxNG
- Date: Mon, 31 Jan 2005 09:41:03 +0100
Daniel Veillard wrote:
Not really. Can you provide the smallest XML files for the
RNG and the XML showing the problem, then we can debug what's actually
happening.
See attachment.
Actually, the error is catched, but the returned diag is not usable.
I wonder if I have to use the lib in an other way in order to get a
usable error message ?
-MP-
-----------------------------------------------------------------------
Marc POINOT Alias: marcvs Email: poinot onera fr
ONERA -MFE/DSNA/ELSA Tel: 01.46.73.42.84 Info: elsa-info onera fr
29, Div. Leclerc Fax: 01.46.73.41.66 Site:
92322 Chatillon FRANCE Project: elsA Web: http://www.onera.fr
<DimensionalUnits_t
Name="DimensionalUnits"
LengthUnits="Meter"
TimeUnits="Second"
/>
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<define name="DimensionalUnits_t">
<element name="DimensionalUnits_t">
<attribute name="Name">
<value type="string">DimensionalUnits</value>
</attribute>
<interleave>
<attribute name="LengthUnits">
<ref name="LengthUnits_t"/>
</attribute>
<attribute name="TimeUnits">
<ref name="TimeUnits_t"/>
</attribute>
</interleave>
</element>
</define>
<define name="LengthUnits_t">
<choice>
<value>Meter</value>
<value>Centimeter</value>
<value>Millimeter</value>
</choice>
</define>
<define name="TimeUnits_t">
<choice>
<value>Second</value>
<value>UserDefined</value>
</choice>
</define>
<start>
<ref name="DimensionalUnits_t" />
</start>
</grammar>
#!/usr/bin/env python
# TESTED with v2.6.17 on SGI IRIX 6.5 (native compiler mode -64)
# Python 2.3.4
# [1] Test it without chage -> ok
# [2] Change an enumnerate value to invalid (e.g. in enumData.xml
# set "Meters" instead of "Meter" -> error code cannot give any info
# on line, attribute name, etc...
# -> very difficult to handle when you have thousand of xml lines !
import libxml2
schema_name="enumGrammar.rng"
data_name="enumData.xml"
# schema
inputs = open(schema_name, 'r')
schema = inputs.read()
inputs.close()
# XML target file
inputd = open(data_name, 'r')
data = inputd.read()
inputd.close()
# error handler
def myParseError(localcontext,unused):
e = libxml2.lastError()
print "file :", e.file()
print "level:", e.level()
print "line :", e.line()
print "msg :", e.message()
# rng parser
libxml2.registerErrorHandler(myParseError,"%s Schema Syntax"%schema_name)
rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
rngs = rngp.relaxNGParse()
# xml doc
ctxt = rngs.relaxNGNewValidCtxt()
doc = libxml2.parseDoc(data)
ret = doc.relaxNGValidateDoc(ctxt)
# last line
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]