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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:parsing': 0.09; 'subject:xml': 0.09; '"system': 0.16; 'nodes': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; 'import': 0.22; 'candidates': 0.23; 'header:User- Agent:1': 0.23; 'subject:problem': 0.24; 'header:X-Complaints- To:1': 0.27; 'matching': 0.30; 'node': 0.31; 'skip:= 40': 0.31; 'option': 0.32; 'subject:the': 0.34; "can't": 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'in:': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'break': 0.61; 'further': 0.61; 'places': 0.64; 'subject:skip:g 10': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: xml problem in parsing the great grandchildren
Date Thu, 13 Nov 2014 10:47:04 +0100
Organization None
References <CAFo8oMAm2TdfeAX582=cWUF5-HSRE_a0feWS+pEPt_TYf6TmGw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd818b.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15770.1415872039.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415872039 news.xs4all.nl 2963 [2001:888:2000:d::a6]:38745
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80676

Show key headers only | 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