def test_namespace_cleanup_keep_prefixes_top(self):
xml = ('<root xmlns:n64="NS64" xmlns:unused1="UNUSED" xmlns:no="NO">'
'<sub xmlns:foo="FOO">'
'<a xmlns:unused2="UNUSED"><n64:x xmlns:a="A" a:attr="X"/></a>'
'<foo>foo:bar</foo>'
'</sub>'
'</root>').encode('utf8')
root = self.etree.fromstring(xml)
self.assertEqual(xml, self.etree.tostring(root))
self.etree.cleanup_namespaces(
root,
top_nsmap={'foo': 'FOO', 'unused1': 'UNUSED'},
keep_ns_prefixes=['foo'])
self.assertEqual(
b'<root xmlns:n64="NS64" xmlns:foo="FOO">'
b'<sub>'
b'<a><n64:x xmlns:a="A" a:attr="X"/></a>'
b'<foo>foo:bar</foo>'
b'</sub>'
b'</root>',
self.etree.tostring(root))
评论列表
文章目录