Python2.7: XMLを扱う
sample.xml
<data> <title>サンプルファイル</title> <desc> <text>ほげ</text> </desc> </data>
pythonから上記sample.xmlを呼び出してprintします。
import xml.etree.ElementTree f = "sample.xml" etree = xml.etree.ElementTree.parse(f) # fileをxml形式で読み込み root = xmlDom.getroot() title = root.find(".//title").text.encode('utf_8') text = root.find(".//desc/text").text.encode('utf_8') print title print text
簡単ですが以上です。
- 作者: 高橋麻奈
- 出版社/メーカー: ソフトバンククリエイティブ
- 発売日: 2009/04/21
- メディア: 単行本
- 購入: 1人 クリック: 101回
- この商品を含むブログ (15件) を見る