我目前正在从事一个学术项目,在Java
和XML
. 实际任务是解析XML
,最好将所需的值传递HashMap
给进一步处理。这是实际 XML 的简短片段。
<root>
<BugReport ID = "1">
<Title>"(495584) Firefox - search suggestions passes wrong previous result to form history"</Title>
<Turn>
<Date>'2009-06-14 18:55:25'</Date>
<From>'Justin Dolske'</From>
<Text>
<Sentence ID = "3.1"> Created an attachment (id=383211) [details] Patch v.2</Sentence>
<Sentence ID = "3.2"> Ah. So, there's a ._formHistoryResult in the....</Sentence>
<Sentence ID = "3.3"> The simple fix it to just discard the service's form history result.</Sentence>
<Sentence ID = "3.4"> Otherwise it's trying to use a old form history result that no longer applies for the search string.</Sentence>
</Text>
</Turn>
<Turn>
<Date>'2009-06-19 12:07:34'</Date>
<From>'Gavin Sharp'</From>
<Text>
<Sentence ID = "4.1"> (From update of attachment 383211 [details])</Sentence>
<Sentence ID = "4.2"> Perhaps we should rename one of them to _fhResult just to reduce confusion?</Sentence>
</Text>
</Turn>
<Turn>
<Date>'2009-06-19 13:17:56'</Date>
<From>'Justin Dolske'</From>
<Text>
<Sentence ID = "5.1"> (In reply to comment #3)</Sentence>
<Sentence ID = "5.2"> &gt; (From update of attachment 383211 [details] [details])</Sentence>
<Sentence ID = "5.3"> &gt; Perhaps we should rename one of them to _fhResult just to reduce confusion?</Sentence>
<Sentence ID = "5.4"> Good point.</Sentence>
<Sentence ID = "5.5"> I renamed the one in the wrapper to _formHistResult. </Sentence>
<Sentence ID = "5.6"> fhResult seemed maybe a bit too short.</Sentence>
</Text>
</Turn>
.....
and so on
</BugReport>
有许多像“Justin Dolske”这样的评论者对这份报告发表了评论,而我真正寻找的是评论者列表以及他们在整个 XML 文件中编写的所有句子。类似的东西if(from == justin dolske) getHisAllSentences()
。其他评论者(所有人)也是如此。我尝试了许多不同的方法来获取仅适用于“Justin dolske”或其他评论者的句子,即使是所有使用的通用形式,XPath
但都失败了。我对这些技术很陌生,包括 JAVA 和任何不知道如何实现它的人。SAX
DOM
任何人都可以具体指导我如何使用上述任何技术获得它,或者是否有其他更好的策略来做到这一点?
(注:稍后我想把它放在hashmap
评论者(justin dolske)的位置和值是(所有句子)之类的HashMap (key, value)
地方)key = name
紧急帮助将不胜感激。