def test_attribute_keeps_namespace_prefix_on_merge(self):
etree = self.etree
root = etree.Element('{http://test/ns}root',
nsmap={None: 'http://test/ns'})
sub = etree.Element('{http://test/ns}sub',
nsmap={'test': 'http://test/ns'})
sub.attrib['{http://test/ns}attr'] = 'value'
self.assertEqual(sub.attrib['{http://test/ns}attr'], 'value')
self.assertEqual(
_bytes('<test:sub xmlns:test="http://test/ns" test:attr="value"/>'),
etree.tostring(sub))
root.append(sub)
self.assertEqual(
_bytes('<root xmlns="http://test/ns">'
'<sub xmlns:test="http://test/ns" test:attr="value"/>'
'</root>'),
etree.tostring(root))
评论列表
文章目录