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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -