/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
from xml.etree import ElementTree as ET import re def strip_whitespace(my_string): """Removes spaces, tabs, and newline characters from a string. \s matches any whitespace character, this is equivalent to the class [\t\n\r\f\v].""" return re.sub("\s", "", my_string) my_xml = """ <root> <child>One</child> <child>Two</child> </root> """ my_xml = strip_whitespace(my_xml) element = ET.XML(my_xml) for subelement in element: print subelement.text