VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.30/python/tests/xpathret.py@ 8268

最後變更 在這個檔案從8268是 6076,由 vboxsync 提交於 17 年 前

Merged dmik/s2 branch (r25959:26751) to the trunk.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Date Revision Author Id
檔案大小: 1.3 KB
 
1#!/usr/bin/python -u
2import sys
3import libxml2
4
5#memory debug specific
6libxml2.debugMemory(1)
7
8#
9# A document hosting the nodes returned from the extension function
10#
11mydoc = libxml2.newDoc("1.0")
12
13def foo(ctx, str):
14 global mydoc
15
16 #
17 # test returning a node set works as expected
18 #
19 parent = mydoc.newDocNode(None, 'p', None)
20 mydoc.addChild(parent)
21 node = mydoc.newDocText(str)
22 parent.addChild(node)
23 return [parent]
24
25doc = libxml2.parseFile("tst.xml")
26ctxt = doc.xpathNewContext()
27libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
28res = ctxt.xpathEval("foo('hello')")
29if type(res) != type([]):
30 print "Failed to return a nodeset"
31 sys.exit(1)
32if len(res) != 1:
33 print "Unexpected nodeset size"
34 sys.exit(1)
35node = res[0]
36if node.name != 'p':
37 print "Unexpected nodeset element result"
38 sys.exit(1)
39node = node.children
40if node.type != 'text':
41 print "Unexpected nodeset element children type"
42 sys.exit(1)
43if node.content != 'hello':
44 print "Unexpected nodeset element children content"
45 sys.exit(1)
46
47doc.freeDoc()
48mydoc.freeDoc()
49ctxt.xpathFreeContext()
50
51#memory debug specific
52libxml2.cleanupParser()
53if libxml2.debugMemory(1) == 0:
54 print "OK"
55else:
56 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
57 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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