5 # Memory debug specific
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>
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
28 dest.addChild(fragment)
29 # do the namespace fixup
30 dest.reconciliateNs(target)
32 # The source tree can be freed at that point
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"
42 # Memory debug specific
43 libxml2.cleanupParser()
44 if libxml2.debugMemory(1) == 0:
47 print "Memory leak %d bytes" % (libxml2.debugMemory(1))