Debian Codegraph @

python/tests/attribs.py

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