VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/python/tests/reader5.py@ 105635

最後變更 在這個檔案從105635是 104106,由 vboxsync 提交於 10 月 前

libxml2-2.9.14: Applied and adjusted our libxml2 changes to 2.9.14. bugref:10640

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 1.3 KB
 
1#!/usr/bin/env python3
2#
3# this tests the Expand() API of the xmlTextReader interface
4# this extract the Dragon bibliography entries from the XML specification
5#
6import setup_test
7import libxml2
8import os
9import sys
10
11# Memory debug specific
12libxml2.debugMemory(1)
13
14expect="""<bibl id="Aho" key="Aho/Ullman">Aho, Alfred V.,
15Ravi Sethi, and Jeffrey D. Ullman.
16<emph>Compilers: Principles, Techniques, and Tools</emph>.
17Reading: Addison-Wesley, 1986, rpt. corr. 1988.</bibl>"""
18
19basedir = os.path.dirname(os.path.realpath(__file__))
20f = open(os.path.join(basedir, '../../test/valid/REC-xml-19980210.xml'), 'rb')
21input = libxml2.inputBuffer(f)
22reader = input.newTextReader("REC")
23res=""
24while reader.Read() > 0:
25 while reader.Name() == 'bibl':
26 node = reader.Expand() # expand the subtree
27 if node.xpathEval("@id = 'Aho'"): # use XPath on it
28 res = res + node.serialize()
29 if reader.Next() != 1: # skip the subtree
30 break;
31
32if res != expect:
33 print("Error: didn't get the expected output")
34 print("got '%s'" % (res))
35 print("expected '%s'" % (expect))
36
37
38#
39# cleanup
40#
41del input
42del reader
43
44# Memory debug specific
45libxml2.cleanupParser()
46if libxml2.debugMemory(1) == 0:
47 print("OK")
48else:
49 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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