First time parsing XML in Python: this can't be like like it was meant to be, can it? -


i need read data xml file , using elementtree. reading number of nodes looks atm:

  def read_edl_ev_ids(xml_tree):       # read edl events (those start "edl_ev_") xml        # , put them dict        # symbolic name key , number value. xml looks like:       # <...>       # <compu-method>       #    <short-name>dt_edl_eventtype</short-name>       #    <...>        #    <compu-scale>       #       <lower_limit>number</lower-limit>       #       <....>       #       <compu-const>       #          <vt>edl_ev_symbolic_name</vt>       #       </compu-const>       #    </compu-scale>       # </compu-method>       edl_ev = {}       node in xml_tree.findall('.//compu-method'):           if node.find('./short-name').text() == 'dt_edl_eventtype':               subnode in node.findall('.//compu-scale'):                   lower_limit = subnode.find('./lower-limit').text()                   edl_ev_name = subnode.find('./compu-const/vt').text()                   if edl_ev_name.startswith('edl_ev_'):                       edl_ev[edl_ev_name] = lower_limit or '0'        return edl_ev 

to sum up: don't it. xml-parsing beginners code , ugly/tedious maintain/unflexible/dry-violating/etc... there better (declarative?) way read in xml?

try taking @ llml library's examples. (look here) think you'll want take @ xpath function


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -