Android decoding html in xml file

懵懂的女人 提交于 2019-11-29 17:09:42

I have two approaches to suggest:

  1. Deactivate validation: factory.setValidating(false);

  2. Add a XHTML DTD tag to your XML stream, immediately after the <?xml ...> tag.

    <?xml version="1.0"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Charly Baquero

I think it iss because it detect "'" apostrophe as a final of string. I've founded a solution.

String stringDatosEntrada = new Scanner(urlConnection.getInputStream()).useDelimiter("\\A").next().replaceAll("&amp;#39;","\'").replaceAll("&#39;","\'");

InputStream is = new ByteArrayInputStream(stringDatosEntrada.getBytes());
Document dom = builder.parse(inputStream)
Scoobler

You could try using androids Html tag editor. It should do what you want, it doesn't recognise all HTML but it does seem to work to convert strings:

    Html.fromHtml(inputstream)

Here is a simple example:

    TextView tv = (TextView) findViewById(R.id.tv);
    String s = "<b>This is</b> my first <u>HTML String</u> &amp; it works well!";
    tv.setText(Html.fromHtml(s));

Here is the output:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!