VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/python/tests/cutnpaste.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
2import sys
3import setup_test
4import libxml2
5
6# Memory debug specific
7libxml2.debugMemory(1)
8
9#
10# Testing XML document serialization
11#
12source = libxml2.parseDoc("""<?xml version="1.0"?>
13<root xmlns:foo="http://example.org/foo"
14 xmlns:bar="http://example.org/bar">
15<include xmlns="http://example.org/include">
16<fragment><foo:elem bar="tricky"/></fragment>
17</include>
18</root>
19""")
20
21target = libxml2.parseDoc("""<?xml version="1.0"?>
22<root xmlns:foobar="http://example.org/bar"/>""")
23
24fragment = source.xpathEval("//*[name()='fragment']")[0]
25dest = target.getRootElement()
26
27# do a cut and paste operation
28fragment.unlinkNode()
29dest.addChild(fragment)
30# do the namespace fixup
31dest.reconciliateNs(target)
32
33# The source tree can be freed at that point
34source.freeDoc()
35
36# check the resulting tree
37str = dest.serialize()
38if 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>""":
39 print("reconciliateNs() failed")
40 sys.exit(1)
41target.freeDoc()
42
43# Memory debug specific
44libxml2.cleanupParser()
45if libxml2.debugMemory(1) == 0:
46 print("OK")
47else:
48 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