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


Groups > comp.lang.python > #80676 > unrolled thread

Re: xml problem in parsing the great grandchildren

Started byPeter Otten <__peter__@web.de>
First post2014-11-13 10:47 +0100
Last post2014-11-13 10:47 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#80676 — Re: xml problem in parsing the great grandchildren

FromPeter Otten <__peter__@web.de>
Date2014-11-13 10:47 +0100
SubjectRe: xml problem in parsing the great grandchildren
Message-ID<mailman.15770.1415872039.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web