Reputation: 837
I have a html view get from asset. But i want to parsing <ul><li>Category 1</li></ul>
to be charsequence array, so I can put it into listview.
My HTML data:
<html>
<body>
<ul>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>Category 4</li>
</ul>
</body>
</html>
I want to get result
CharSequence[] myList={"Category 1","Category 2","Category 3","Category 4"};
Thanks very much.
Upvotes: 0
Views: 529
Reputation: 136
a bit strange to use a local html asset as a datasource for a listview, but anyway..
To extract the contents of the tags into an charsequence array you could use something like this
List<String> tagValues = new ArrayList<String>();
final Matcher matcher = Pattern.compile("<li>(.+?)</li>").matcher(theStringWithTags);
while (matcher.find()) {
tagValues.add(matcher.group(1));
}
CharSequence[] cs = tagValues.toArray(new CharSequence[tagValues.size()]);
Cheers, Marcus
Upvotes: 1
Reputation: 12179
You can use HtmlCleaner and XPATH.
You can take a look on this examples :
Using XPATH and HTML Cleaner to parse HTML / XML
Here
Upvotes: 0