dtdvalid.py 616 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/python -u
  2. import libxml2
  3. import sys
  4. # Memory debug specific
  5. libxml2.debugMemory(1)
  6. dtd="""<!ELEMENT foo EMPTY>"""
  7. instance="""<?xml version="1.0"?>
  8. <foo></foo>"""
  9. dtd = libxml2.parseDTD(None, 'test.dtd')
  10. ctxt = libxml2.newValidCtxt()
  11. doc = libxml2.parseDoc(instance)
  12. ret = doc.validateDtd(ctxt, dtd)
  13. if ret != 1:
  14. print "error doing DTD validation"
  15. sys.exit(1)
  16. doc.freeDoc()
  17. dtd.freeDtd()
  18. del dtd
  19. del ctxt
  20. # Memory debug specific
  21. libxml2.cleanupParser()
  22. if libxml2.debugMemory(1) == 0:
  23. print "OK"
  24. else:
  25. print "Memory leak %d bytes" % (libxml2.debugMemory(1))
  26. libxml2.dumpMemory()