VirtualBox

source: vbox/trunk/src/libs/libxml2-2.9.4/python/tests/cutnpaste.py@ 90880

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

libxml 2.9.4: fix export

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
檔案大小: 1.3 KB
 
1#!/usr/bin/python -u
2import sys
3import libxml2
4
5# Memory debug specific
6libxml2.debugMemory(1)
7
8#
9# Testing XML document serialization
10#
11source = libxml2.parseDoc("""<?xml version="1.0"?>
12<root xmlns:foo="http://example.org/foo"
13 xmlns:bar="http://example.org/bar">
14<include xmlns="http://example.org/include">
15<fragment><foo:elem bar="tricky"/></fragment>
16</include>
17</root>
18""")
19
20target = libxml2.parseDoc("""<?xml version="1.0"?>
21<root xmlns:foobar="http://example.org/bar"/>""")
22
23fragment = source.xpathEval("//*[name()='fragment']")[0]
24dest = target.getRootElement()
25
26# do a cut and paste operation
27fragment.unlinkNode()
28dest.addChild(fragment)
29# do the namespace fixup
30dest.reconciliateNs(target)
31
32# The source tree can be freed at that point
33source.freeDoc()
34
35# check the resulting tree
36str = dest.serialize()
37if str != """<root xmlns:foobar="http://example.org/bar" xmlns:default="http://example.org/include" xmlns:foo="http://example.org/foo"><default:fragment><foo:elem bar="tricky"/></default:fragment></root>""":
38 print("reconciliateNs() failed")
39 sys.exit(1)
40target.freeDoc()
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