Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(27476)

Unified Diff: Lib/xml/etree/ElementTree.py

Issue 18304: ElementTree -- provide a way to ignore namespace in tags and seaches
Patch Set: Created 3 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_xml_etree.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/xml/etree/ElementTree.py Wed Jul 27 16:59:22 2016 +0200
+++ b/Lib/xml/etree/ElementTree.py Wed Jul 27 19:56:56 2016 +0200
@@ -536,6 +536,24 @@
return self.text == other.text
return self.text == other
+
+def strip_namespaces(tree):
+ """Remove all namespaces from tags and attributes in place.
+
+ Leaves only the local names in the subtree.
+ """
+ for el in tree.iter():
+ tag = el.tag
+ if tag and isinstance(tag, str) and tag[0] == '{':
+ el.tag = tag.partition('}')[2]
+ attrib = el.attrib
+ if attrib:
+ for name, value in list(attrib.items()):
+ if name and isinstance(name, str) and name[0] == '{':
+ del attrib[name]
+ attrib[name.partition('}')[2]] = value
+
+
# --------------------------------------------------------------------
« no previous file with comments | « Lib/test/test_xml_etree.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+