0

I have this HTML i am parsing.

<div id="articleHeader">
<h1 class="headline">Assassin's Creed Revelations: The Three Heroes</h1>
<h2 class="subheadline">Exclusive videos and art spanning three eras of assassins.</h2>
<h2 class="publish-date"><script>showUSloc=(checkLocale('uk')||checkLocale('au'));document.writeln(showUSloc ? '<strong>US, </strong>' : '');</script>

<span class="us_details">September 22, 2011</span>

What i want to do it parse the "headline" subheadline and publish date all to seperate Strings

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
  • Check out this previously asked question: http://stackoverflow.com/questions/2188049/parse-html-in-android – slayton Sep 23 '11 at 03:06

2 Answers2

2

Just use the proper CSS selectors to grab them.

Document document = Jsoup.connect(url).get();
String headline = document.select("#articleHeader .headline").text();
String subheadline = document.select("#articleHeader .subheadline").text();
String us_details = document.select("#articleHeader .us_details").text();
// ...

Or a tad more efficient:

Document document = Jsoup.connect(url).get();
Element articleHeader = document.select("#articleHeader").first();
String headline = articleHeader.select(".headline").text();
String subheadline = articleHeader.select(".subheadline").text();
String us_details = articleHeader.select(".us_details").text();
// ...
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Android has a SAX parser built into it . You can use other standard XML parsers as well.

But I think if ur HTML is simple enough u could use RegEx to extract string.

the100rabh
  • 4,077
  • 4
  • 32
  • 40