VirtualBox

source: vbox/trunk/src/libs/libxml2-2.9.4/python/tests/reader5.py@ 76389

最後變更 在這個檔案從76389是 65950,由 vboxsync 提交於 8 年 前

libxml 2.9.4: fix export

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

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