def testRemoveNode(self): # create a tree then remove the child doc = XMLFragment() doc.addNode("/root/child") doc.removeNode("/root/child") self.assertEqual(doc.serialize(), '<?xml version="1.0"?>\n<root/>\n') # create a tree then remove the second child doc = XMLFragment() doc.addNode("/root/child") doc.addNode("/root/child") doc.removeNode("/root/child[2]") self.assertEqual(doc.serialize(), '<?xml version="1.0"?>\n<root><child/></root>\n')
def testRemoveNodeNs(self): namespaces = {'t': "test", 's': "test2"} # Test deleting a node that's in a namespace doc = XMLFragment() #doc.registerNamespaces(namespaces) doc.addNode("/root/t:child") doc.removeNode("/root/t:child") self.assertEqual(doc.serialize(), '<?xml version="1.0"?>\n<root xmlns:t="test"/>\n') # create a tree then remove the second child doc = XMLFragment() #doc.registerNamespaces(namespaces) doc.addNode("/root/t:child") doc.addNode("/root/t:child") doc.removeNode("/root/t:child[2]") self.assertEqual(doc.serialize(), '<?xml version="1.0"?>\n<root xmlns:t="test"><t:child/></root>\n')