3 # this tests the Expand() API of the xmlTextReader interface
4 # this extract the Dragon bibliography entries from the XML specification
10 # Memory debug specific
11 libxml2.debugMemory(1)
13 expect="""<bibl id="Aho" key="Aho/Ullman">Aho, Alfred V.,
14 Ravi Sethi, and Jeffrey D. Ullman.
15 <emph>Compilers: Principles, Techniques, and Tools</emph>.
16 Reading: Addison-Wesley, 1986, rpt. corr. 1988.</bibl>"""
18 f = open('../../test/valid/REC-xml-19980210.xml')
19 input = libxml2.inputBuffer(f)
20 reader = input.newTextReader("REC")
23 while reader.Name() == 'bibl':
24 node = reader.Expand() # expand the subtree
25 if node.xpathEval("@id = 'Aho'"): # use XPath on it
26 res = res + node.serialize()
27 if reader.Next() != 1: # skip the subtree
31 print "Error: didn't get the expected output"
32 print "got '%s'" % (res)
33 print "expected '%s'" % (expect)
42 # Memory debug specific
43 libxml2.cleanupParser()
44 if libxml2.debugMemory(1) == 0:
47 print "Memory leak %d bytes" % (libxml2.debugMemory(1))