回答編集履歴
2
追記
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
#### 補足
|
6
6
|
|
7
|
-
`.attrib['id']`で取得できないでしょうか?
|
7
|
+
属性値を取得したいのであれば`.attrib['id']`で取得できないでしょうか?
|
8
8
|
|
9
9
|
```Python
|
10
10
|
|
1
補足
test
CHANGED
@@ -1 +1,31 @@
|
|
1
1
|
質問文ちゃんと理解できていませんが過去質問[PythonでElementTreeでXMLのテキストを抽出中にprefix mapエラーが出る](https://teratail.com/questions/162215)が参考になるかと思います。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
#### 補足
|
6
|
+
|
7
|
+
`.attrib['id']`で取得できないでしょうか?
|
8
|
+
|
9
|
+
```Python
|
10
|
+
|
11
|
+
import xml.etree.ElementTree as ET
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
tree = ET.parse('demo.xml')
|
16
|
+
|
17
|
+
root = tree.getroot()
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
id = root.find(".//{http://www.w3.org/2000/Atom}entry/{http://www.w3.org/2000/Atom}id")
|
22
|
+
|
23
|
+
print(id.text) # 12345
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
id_board = root.find('.//board:folder', {'board': 'http://www.develop.com/board'})
|
28
|
+
|
29
|
+
print(id_board.attrib['id']) # 54321
|
30
|
+
|
31
|
+
```
|