Skip to content

Instantly share code, notes, and snippets.

@radaniba
Created November 29, 2012 17:08
Show Gist options
  • Select an option

  • Save radaniba/4170445 to your computer and use it in GitHub Desktop.

Select an option

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
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