Annotation of embedaddon/libxml2/python/tests/reader5.py, revision 1.1.1.2
1.1 misho 1: #!/usr/bin/python -u
2: #
3: # this tests the Expand() API of the xmlTextReader interface
4: # this extract the Dragon bibliography entries from the XML specification
5: #
6: import libxml2
7: import sys
8:
9: # Memory debug specific
10: libxml2.debugMemory(1)
11:
12: expect="""<bibl id="Aho" key="Aho/Ullman">Aho, Alfred V.,
13: Ravi Sethi, and Jeffrey D. Ullman.
14: <emph>Compilers: Principles, Techniques, and Tools</emph>.
15: Reading: Addison-Wesley, 1986, rpt. corr. 1988.</bibl>"""
16:
1.1.1.2 ! misho 17: f = open('../../test/valid/REC-xml-19980210.xml', 'rb')
1.1 misho 18: input = libxml2.inputBuffer(f)
19: reader = input.newTextReader("REC")
20: res=""
1.1.1.2 ! misho 21: while reader.Read() > 0:
1.1 misho 22: while reader.Name() == 'bibl':
23: node = reader.Expand() # expand the subtree
24: if node.xpathEval("@id = 'Aho'"): # use XPath on it
25: res = res + node.serialize()
26: if reader.Next() != 1: # skip the subtree
27: break;
28:
29: if res != expect:
1.1.1.2 ! misho 30: print("Error: didn't get the expected output")
! 31: print("got '%s'" % (res))
! 32: print("expected '%s'" % (expect))
1.1 misho 33:
34:
35: #
36: # cleanup
37: #
38: del input
39: del reader
40:
41: # Memory debug specific
42: libxml2.cleanupParser()
43: if libxml2.debugMemory(1) == 0:
1.1.1.2 ! misho 44: print("OK")
1.1 misho 45: else:
1.1.1.2 ! misho 46: print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
1.1 misho 47: libxml2.dumpMemory()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>