Pythonのお勉強 Part3000.12
■ このスレッドは過去ログ倉庫に格納されています
0332デフォルトの名無しさん
2006/09/02(土) 00:37:52とりあえずエレメントとか属性とか無茶ですが
以下のようなXMLがあったとします。
<?xml version = "1.0" encoding = "utf-8"?>
<person>
<aperson no = "123">
<name>Yamada Hanako</name>
<age>18</age>
<sex>female</sex>
</aperson>
<aperson no = "124">
<name>aaa Hanako</name>
<age>18</age>
<sex>female</sex>
</aperson>
</person>
これから、例えばaperson no = "124"のageのデータを取りたい場合
どうやれば効率がよいでしょうか?
思いついたのは、
lst = root.findall('aperson')
for item in lst:
if item.get("no") = "124":
124root= item
break
print 124root.find('age').text
ぐらいなんですが;;
findの後のxpathって属性まで検索対象にできないんですよね?
よく分からないけどlst = root.findall('aperson@no=124')みたいに
■ このスレッドは過去ログ倉庫に格納されています