Re: [xml] Error report with RelaxNG

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

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 ?

 Marc POINOT             Alias: marcvs        Email: poinot onera fr
 ONERA -MFE/DSNA/ELSA    Tel:  Info: elsa-info onera fr
 29, Div. Leclerc        Fax:  Site:     
 92322 Chatillon FRANCE  Project: elsA        Web:
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns=""; 
  <define name="DimensionalUnits_t">
    <element name="DimensionalUnits_t">
      <attribute name="Name">
        <value type="string">DimensionalUnits</value>
        <attribute name="LengthUnits">
          <ref name="LengthUnits_t"/>
        <attribute name="TimeUnits">
          <ref name="TimeUnits_t"/>
  <define name="LengthUnits_t">
  <define name="TimeUnits_t">
    <ref name="DimensionalUnits_t" />
#!/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
inputs = open(schema_name, 'r')
schema =

# XML target file
inputd = open(data_name, 'r')
data =

# 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]