Android decoding html in xml file

后端 未结 3 417
离开以前
离开以前 2020-12-22 03:54

In my software im receiving a xml file that is containing some HTML entities like & amp; or whatever. Im successfull decoding the xml but not the HTML entities. The stri

相关标签:
3条回答
  • 2020-12-22 04:09

    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("'","\'").replaceAll("'","\'");
    
    InputStream is = new ByteArrayInputStream(stringDatosEntrada.getBytes());
    Document dom = builder.parse(inputStream)
    
    0 讨论(0)
  • 2020-12-22 04:11

    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">

    0 讨论(0)
  • 2020-12-22 04:29

    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:

    0 讨论(0)
提交回复
热议问题