使用JSoup获取与xml标记相邻的int

时间:2015-04-28 08:45:20

标签: jsoup

这就是我的数据:

<sentence> 0
A sports article in some copies on Sunday about <LOCATION>Boston</LOCATION> 's 1-0 victory against <LOCATION>San Francisco</LOCATION> referred incorrectly to the history of the interleague series between the <ORGANIZATION>Red Sox</ORGANIZATION> and the <ORGANIZATION>Giants</ORGANIZATION> .
</sentence>

<sentence> 1
This was their first meeting since June 2004 -- not since the World Series in 1912 , the year they last played each other at <LOCATION>Fenway Park</LOCATION> .
</sentence>

使用jsoup我想得到<sentence>右边的int,怎么做?

1 个答案:

答案 0 :(得分:0)

这很容易:

Document doc = Jsoup.parse(everything);

Elements contents = doc.getElementsByTag("sentence");
for (Element content : contents)  {
    String pers = content.select("sentence").text();
    pers = pers.substring(0, pers.indexOf(" ")); 
    System.out.println(pers);
}