开发者

Android: Html.fromHtml() handle non-standard html tags

I am parsing an html message which may contain user-defined tags, e.g. <usertag uservalue="value" />.

I am using standard Html.fromHtml() function to parse the html source. Unfortunately it simply ignores non-standard tags and remove these from the output. I would like to keep them.

I've tried to supply my own TagHandler to the fromHtml() function, but I do not know what to do inside the handleTag() function. Looks like I do not have access to the non-standard tag attributes\content from the TagHandler.handleTag() function? How do I use xmlReader passed inside f开发者_C百科romHtml()?

Thanks


I am parsing an html message which may contain user-defined tags, e.g. <usertag uservalue="value" />.

Then you do not have HTML.

Here are some options:

  1. Get rid of the "user-defined tags" outright
  2. Have your source markup be valid HTML, with your "user-defined tags" turned into valid HTML (e.g., using <div> and <span> with class attributes, as the microformats people do)
  3. Pre-process your markup to handle your "user-defined tags", turning them into valid HTML, before calling Html.fromHtml()


From what we can see in the javadoc, there seems to be 4 parameters :

  • opening, specifying if this is an opening or closing tab
  • tag, presumably the tag name
  • output, which is the generated Editable to which you'll add your data
  • xmlReader, the current XML reader.

It looks like you can't use the attributes, though.

One last solution, although a little bit complicated, would be to reimplement Html to suit your needs. You can find its source here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜