Skip to content

Instantly share code, notes, and snippets.

@joefutrelle
Created July 25, 2014 14:36
Show Gist options
  • Save joefutrelle/bedac2678dae7fc21c77 to your computer and use it in GitHub Desktop.
Save joefutrelle/bedac2678dae7fc21c77 to your computer and use it in GitHub Desktop.
example of (rather convoluted) way to parse prefixed tag names using etree
from StringIO import StringIO
import xml.etree.ElementTree as ET
mvco_ns = 'http://ifcb-data.whoi.edu/mvco/'
lid = 'IFCB5_2011_033_041857'
nsmap = {'mvco': mvco_ns}
def parse_id(pfx_id, nsmap={}):
ns_statements = ' '.join(['xmlns:%s="%s"' % (k,v) for k,v in nsmap.items()])
xml = '<%s %s/>' % (pfx_id, ns_statements)
return ET.parse(StringIO(xml)).getroot().tag
print parse_id('mvco:%s' % lid, nsmap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment