私はこのxmlファイルを持っています:
<ItemArray>
<Item>
<GiftIcon>0</GiftIcon>
<HitCounter>NoHitCounter</HitCounter>
<Quantity>1</Quantity>
<TimeLeft>P9DT17H35M6S</TimeLeft>
<Title>Table</Title>
</Item>
<Item>
<GiftIcon>0</GiftIcon>
<HitCounter>NoHitCounter</HitCounter>
<Quantity>1</Quantity>
<TimeLeft>PT0S</TimeLeft>
<Title>Chair</Title>
</Item>
</ItemArray>
"TimeLeft" が "PT0S" でない場合は "Title" を返したい:
これまでのところ、私はこれを持っています:
itemList = response.getElementsByTagName('Item')
children = itemList[0].childNodes
for child in children :
if child.tagName == "TimeLeft":
if child.childNodes[0].nodeValue == "PT0S":
print "ping"
しかし、そこから「タイトル」値に戻る方法がわかりません。他の子ノードが true または false であるかどうかに応じて、子ノードの値を返すよりエレガントな方法は何でしょうか?