libxml2 2.9.1 clean sources
[tomato/tomato-dir865l.git] / release / src / router / libxml2 / python / tests / cutnpaste.py
blob7787246b5ae9d266a31121ada56e949b596b5866
1 #!/usr/bin/python -u
2 import sys
3 import libxml2
5 # Memory debug specific
6 libxml2.debugMemory(1)
9 # Testing XML document serialization
11 source = 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 """)
20 target = libxml2.parseDoc("""<?xml version="1.0"?>
21 <root xmlns:foobar="http://example.org/bar"/>""")
23 fragment = source.xpathEval("//*[name()='fragment']")[0]
24 dest = target.getRootElement()
26 # do a cut and paste operation
27 fragment.unlinkNode()
28 dest.addChild(fragment)
29 # do the namespace fixup
30 dest.reconciliateNs(target)
32 # The source tree can be freed at that point
33 source.freeDoc()
35 # check the resulting tree
36 str = dest.serialize()
37 if 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)
40 target.freeDoc()
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()