Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100718
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-12-21 20:29 -0800 |
| Message-ID | <3d2e5064-9cc0-43de-a708-faf528a795ca@googlegroups.com> (permalink) |
| Subject | Newbie XML problem |
| From | KP <kai.peters@gmail.com> |
From my first foray into XML with Python:
I would like to retrieve this list from the XML upon searching for the 'config' with id attribute = 'B'
config = {id: 1, canvas: (3840, 1024), comment: "a comment",
{id: 4, gate: 3, (0, 0, 1280, 1024)},
{id: 5, gate: 2, (1280, 0, 2560, 1024)},
{id: 6, gate: 1, (2560, 0, 3840, 1024)}}
I have started to use this code - but this is beginning to feel very non-elegant; not the cool Python code I usually see...
import xml.etree.ElementTree as ET
tree = ET.parse('master.xml')
master = tree.getroot()
for config in master:
if config.attrib['id'] == 'B':
...
Thanks for any help!
<?xml version="1.0" encoding="UTF-8"?>
<master>
<config id="A">
<canvas>3840,1024</canvas>
<comment>"bla"</comment>
<panel>
<id>1</id>
<gate>6</gate>
<coordinates>0,0,1280,1024</coordinates>
</panel>
<panel>
<id>2</id>
<gate>5</gate>
<coordinates>1280,0,2560,1024</coordinates>
</panel>
<panel>
<id>3</id>
<gate>4</gate>
<coordinates>2560,0,3840,1024</coordinates>
</panel>
</config>
<config id="B">
<canvas>3840,1024</canvas>
<comment>"a comment"</comment>
<panel>
<id>4</id>
<gate>3</gate>
<coordinates>0,0,1280,1024</coordinates>
</panel>
<panel>
<id>5</id>
<gate>2</gate>
<coordinates>1280,0,2560,1024</coordinates>
</panel>
<panel>
<id>6</id>
<gate>1</gate>
<coordinates>2560,0,3840,1024</coordinates>
</panel>
</config>
<master>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Newbie XML problem KP <kai.peters@gmail.com> - 2015-12-21 20:29 -0800 Re: Newbie XML problem Miki Tebeka <miki.tebeka@gmail.com> - 2015-12-21 21:49 -0800 Re: Newbie XML problem jmp <jeanmichel@sequans.com> - 2015-12-22 13:27 +0100 Re: Newbie XML problem KP <kai.peters@gmail.com> - 2015-12-22 11:03 -0800
csiph-web