Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80676

Re: xml problem in parsing the great grandchildren

From Peter Otten <__peter__@web.de>
Subject Re: xml problem in parsing the great grandchildren
Date 2014-11-13 10:47 +0100
Organization None
References <CAFo8oMAm2TdfeAX582=cWUF5-HSRE_a0feWS+pEPt_TYf6TmGw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.15770.1415872039.18130.python-list@python.org> (permalink)

Show all headers | View raw


OmPs wrote:


> import xml.etree.ElementTree as ET
> 
> inv = open('lshw.xml', 'r')
> inv = inv.read()
> inv = ET.XML(inv)
> 
> find_memory =inventory.findall(".//node[@id='bank:*']")
> 
> # I am stuck here. What is required is description of the system memory,
> but system has lot of places where class=memory is used and hence i can't
> use it. i need the one's which has id=bank:0 .. n and collect the
> decryption of it.

 
> I am stuck here. What I am looking for  is description of the system
> memory, but system has lot of places where class=memory is used and hence
> i can't use it. i need the one's which has id=bank:0 .. n and collect the
> decryption of it.
> 
> I don't have option to use lxml.

Take the candidates and then find criteria the further reduce the matching 
nodes until only those are left that you are interested in:

import xml.etree.ElementTree as ET
 
inv = ET.parse("lshw-a105.xml")
 
nodes = inv.findall(".//node[@class='memory']")
for node in nodes:
    description = node.find("./description")
    if description.text == "System Memory":
        for subnode in node.findall("./node"):
            print(subnode.attrib["id"], subnode.find("./description").text)
        break

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: xml problem in parsing the great grandchildren Peter Otten <__peter__@web.de> - 2014-11-13 10:47 +0100

csiph-web