Created
November 29, 2012 17:08
-
-
Save radaniba/4170445 to your computer and use it in GitHub Desktop.
To those who are using large xml files here is a simple python script that could be useful
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment