3 # this tests the Expand() API of the xmlTextReader interface
4 # this extract the Dragon bibliography entries from the XML specification
9 # Memory debug specific
10 libxml2.debugMemory(1)
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>"""
17 f = open('../../test/valid/REC-xml-19980210.xml', 'rb')
18 input = libxml2.inputBuffer(f)
19 reader = input.newTextReader("REC")
21 while reader.Read() > 0:
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
30 print("Error: didn't get the expected output")
31 print("got '%s'" % (res))
32 print("expected '%s'" % (expect))
41 # Memory debug specific
42 libxml2.cleanupParser()
43 if libxml2.debugMemory(1) == 0:
46 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))