Created
July 25, 2014 14:36
-
-
Save joefutrelle/bedac2678dae7fc21c77 to your computer and use it in GitHub Desktop.
example of (rather convoluted) way to parse prefixed tag names using etree
This file contains 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 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