VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.31/python/tests/reader5.py@ 55391

最後變更 在這個檔案從55391是 39915,由 vboxsync 提交於 13 年 前

libxml-2.6.31 unmodified

  • 屬性 svn:eol-style 設為 native
檔案大小: 1.2 KB
 
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#
6import libxml2
7import StringIO
8import sys
9
10# Memory debug specific
11libxml2.debugMemory(1)
12
13expect="""<bibl id="Aho" key="Aho/Ullman">Aho, Alfred V.,
14Ravi Sethi, and Jeffrey D. Ullman.
15<emph>Compilers: Principles, Techniques, and Tools</emph>.
16Reading: Addison-Wesley, 1986, rpt. corr. 1988.</bibl>"""
17
18f = open('../../test/valid/REC-xml-19980210.xml')
19input = libxml2.inputBuffer(f)
20reader = input.newTextReader("REC")
21res=""
22while reader.Read():
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
28 break;
29
30if res != expect:
31 print "Error: didn't get the expected output"
32 print "got '%s'" % (res)
33 print "expected '%s'" % (expect)
34
35
36#
37# cleanup
38#
39del input
40del reader
41
42# Memory debug specific
43libxml2.cleanupParser()
44if libxml2.debugMemory(1) == 0:
45 print "OK"
46else:
47 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
48 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette