0
我有一些XML:minidom命名 - 提取子節點
<sentence id="1086415:2">
<text>$6 and there is much tasty food, all of it fresh and continually refilled.</text>
<Opinions>
<Opinion to="31" from="27" polarity="positive" category="FOOD#STYLE_OPTIONS" target="food"/>
<Opinion to="31" from="27" polarity="positive" category="FOOD#QUALITY" target="food"/>
<Opinion to="31" from="27" polarity="positive" category="FOOD#PRICES" target="food"/>
</Opinions>
</sentence>
<sentence id="1086415:3">
<text>I am not a vegetarian but, almost all the dishes were great.</text>
<Opinions>
<Opinion to="48" from="42" polarity="positive" category="FOOD#QUALITY" target="dishes"/>
</Opinions>
我試圖給意見標籤內的所有內容解壓到夫婦它與一個元組的文本。我想知道我怎麼可以用minidom來做到這一點?目前意見返回'\ n'。
from xml.dom import minidom
xmldoc = minidom.parse("ABSA16_Restaurants_Train_SB1_v2.xml")
sentences = xmldoc.getElementsByTagName("sentence")
for sentence in sentences:
text = sentence.getElementsByTagName("text")[0].firstChild.data
opinion = sentence.getElementsByTagName("Opinions")[0].firstChild.data
謝謝。