12 def handler(self, msg, data):
14 raise Exception, "Error handler did not receive correct argument"
15 self.errors.append(msg)
18 # Memory debug specific
19 libxml2.debugMemory(1)
21 dtd="""<!ELEMENT foo EMPTY>"""
22 valid="""<?xml version="1.0"?>
25 invalid="""<?xml version="1.0"?>
28 dtd = libxml2.parseDTD(None, 'test.dtd')
29 ctxt = libxml2.newValidCtxt()
31 ctxt.setValidityErrorHandler(e.handler, e.handler, ARG)
34 doc = libxml2.parseDoc(valid)
35 ret = doc.validateDtd(ctxt, dtd)
36 if ret != 1 or e.errors:
37 print "error doing DTD validation"
41 # Test invalid document
42 doc = libxml2.parseDoc(invalid)
43 ret = doc.validateDtd(ctxt, dtd)
44 if ret != 0 or not e.errors:
45 print "Error: document supposed to be invalid"
52 # Memory debug specific
53 libxml2.cleanupParser()
54 if libxml2.debugMemory(1) == 0:
57 print "Memory leak %d bytes" % (libxml2.debugMemory(1))