12 def handler(self, msg, data):
14 raise Exception, "Error handler did not receive correct argument"
15 self.errors.append(msg)
17 # Memory debug specific
18 libxml2.debugMemory(1)
20 schema="""<?xml version="1.0"?>
22 xmlns="http://relaxng.org/ns/structure/1.0"
23 xmlns:a="http://relaxng.org/ns/annotation/1.0"
24 xmlns:ex1="http://www.example.com/n1"
25 xmlns:ex2="http://www.example.com/n2">
26 <a:documentation>A foo element.</a:documentation>
27 <element name="ex1:bar1">
30 <element name="ex2:bar2">
36 valid="""<?xml version="1.0"?>
37 <foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1"/><pre2:bar2 xmlns:pre2="http://www.example.com/n2"/></foo>"""
39 invalid="""<?xml version="1.0"?>
40 <foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1">bad</pre1:bar1><pre2:bar2 xmlns:pre2="http://www.example.com/n2"/></foo>"""
42 rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
43 rngs = rngp.relaxNGParse()
44 ctxt = rngs.relaxNGNewValidCtxt()
46 ctxt.setValidityErrorHandler(e.handler, e.handler, ARG)
49 doc = libxml2.parseDoc(valid)
50 ret = doc.relaxNGValidateDoc(ctxt)
51 if ret != 0 or e.errors:
52 print "error doing RelaxNG validation"
56 # Test invalid document
57 doc = libxml2.parseDoc(invalid)
58 ret = doc.relaxNGValidateDoc(ctxt)
59 if ret == 0 or not e.errors:
60 print "Error: document supposed to be RelaxNG invalid"
67 libxml2.relaxNGCleanupTypes()
69 # Memory debug specific
70 libxml2.cleanupParser()
71 if libxml2.debugMemory(1) == 0:
74 print "Memory leak %d bytes" % (libxml2.debugMemory(1))