回答編集履歴

5

直線の回答と同じ検索内容に変更

2022/09/30 09:44

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  tree = ET.parse('result.xml')
19
19
  root = tree.getroot()
20
- text = root.find('text')
20
+ text = root.find('.//text')
21
21
  print("textがありません" if text is None else text.text)
22
22
  ```
23
23
 

4

text有無判定処理修正

2022/09/30 09:42

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -18,7 +18,7 @@
18
18
  tree = ET.parse('result.xml')
19
19
  root = tree.getroot()
20
20
  text = root.find('text')
21
- print(text.text if text else "textがありません")
21
+ print("textがありません" if text is None else text.text)
22
22
  ```
23
23
 
24
24
  ```text:実行結果

3

textがNoneだったときの処理を追記

2022/09/30 09:39

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -17,7 +17,8 @@
17
17
 
18
18
  tree = ET.parse('result.xml')
19
19
  root = tree.getroot()
20
- print(root.find('text').text)
20
+ text = root.find('text')
21
+ print(text.text if text else "textがありません")
21
22
  ```
22
23
 
23
24
  ```text:実行結果

2

result.xml追記、コード変更、実行結果追記

2022/09/30 09:33

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -1,4 +1,26 @@
1
- ```py
2
- print(ET.parse('result.xml').getroot().find('text').text)
1
+ ```result.xml
2
+ <passage>
3
+ <infon key="section_type">ABSTRACT</infon>
4
+ <infon key="type">abstract</infon> <offset>81</offset>
5
+ <text>Neurologic complications of COVID-19 infection have been recently described and include dizziness, headache, loss of taste and smell, stroke, and encephalopathy. Brain MRI in these patients have revealed various findings including ischemia, hemorrhage, inflammation, and demyelination. In this article, we report a case of critical illness-associated cerebral microbleeds identified on MRI in a patient with severe COVID-19 infection and discuss the potential etiologies of these neuroimaging findings.</text>
6
+ <annotation id="20">
7
+ <infon key="identifier">9606</infon>
8
+ <infon key="type">Species</infon>
9
+ <location offset="262" length="8"/>
10
+ <text>patients</text>
11
+ </annotation>
12
+ </passage>
3
13
  ```
4
14
 
15
+ ```py
16
+ import xml.etree.ElementTree as ET
17
+
18
+ tree = ET.parse('result.xml')
19
+ root = tree.getroot()
20
+ print(root.find('text').text)
21
+ ```
22
+
23
+ ```text:実行結果
24
+ Neurologic complications of COVID-19 infection have been recently described and include dizziness, headache, loss of taste and smell, stroke, and encephalopathy. Brain MRI in these patients have revealed various findings including ischemia, hemorrhage, inflammation, and demyelination. In this article, we report a case of critical illness-associated cerebral microbleeds identified on MRI in a patient with severe COVID-19 infection and discuss the potential etiologies of these neuroimaging findings.
25
+ ```
26
+

1

一行にまとめる

2022/09/30 08:43

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -1,5 +1,4 @@
1
1
  ```py
2
- text = tree.getroot().find('text').text
2
+ print(ET.parse('result.xml').getroot().find('text').text)
3
- print(text)
4
3
  ```
5
4