Last change
on this file since 7979 was 6076, checked in by vboxsync, 17 years ago |
Merged dmik/s2 branch (r25959:26751) to the trunk.
|
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Date Revision Author Id
|
File size:
1.2 KB
|
Line | |
---|
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 | #
|
---|
6 | import libxml2
|
---|
7 | import StringIO
|
---|
8 | import sys
|
---|
9 |
|
---|
10 | # Memory debug specific
|
---|
11 | libxml2.debugMemory(1)
|
---|
12 |
|
---|
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>"""
|
---|
17 |
|
---|
18 | f = open('../../test/valid/REC-xml-19980210.xml')
|
---|
19 | input = libxml2.inputBuffer(f)
|
---|
20 | reader = input.newTextReader("REC")
|
---|
21 | res=""
|
---|
22 | while 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 |
|
---|
30 | if 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 | #
|
---|
39 | del input
|
---|
40 | del reader
|
---|
41 |
|
---|
42 | # Memory debug specific
|
---|
43 | libxml2.cleanupParser()
|
---|
44 | if libxml2.debugMemory(1) == 0:
|
---|
45 | print "OK"
|
---|
46 | else:
|
---|
47 | print "Memory leak %d bytes" % (libxml2.debugMemory(1))
|
---|
48 | libxml2.dumpMemory()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.