attribs.py 816 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/python -u
  2. import sys
  3. import libxml2
  4. # Memory debug specific
  5. libxml2.debugMemory(1)
  6. #
  7. # Testing XML document serialization
  8. #
  9. doc = libxml2.parseDoc(
  10. """<?xml version="1.0" encoding="iso-8859-1"?>
  11. <!DOCTYPE test [
  12. <!ELEMENT test (#PCDATA) >
  13. <!ATTLIST test xmlns:abc CDATA #FIXED "http://abc.org" >
  14. <!ATTLIST test abc:attr CDATA #FIXED "def" >
  15. ]>
  16. <test />
  17. """)
  18. elem = doc.getRootElement()
  19. attr = elem.hasNsProp('attr', 'http://abc.org')
  20. if attr == None or attr.serialize()[:-1] != """<!ATTLIST test abc:attr CDATA #FIXED "def">""":
  21. print "Failed to find defaulted attribute abc:attr"
  22. sys.exit(1)
  23. doc.freeDoc()
  24. # Memory debug specific
  25. libxml2.cleanupParser()
  26. if libxml2.debugMemory(1) == 0:
  27. print "OK"
  28. else:
  29. print "Memory leak %d bytes" % (libxml2.debugMemory(1))
  30. libxml2.dumpMemory()