【问题标题】:How to restore html content in java?如何在java中恢复html内容?
【发布时间】:2016-08-22 14:01:25
【问题描述】:

我正在将一些 html 代码作为文本保存到 mysql 数据库中。我使用 volley 将该文本作为字符串检索。当我保存 html 时,某些不需要的值会添加到 html 内容中。如何删除这些不需要的内容并显示 html 内容。我正在使用 webview 来显示此内容并使用 jsoup 来解析它。 这是我使用Document doc = Jsoup.parse(instruction);解析html内容后得到的结果

 <html>
   <head></head>
   <body>
      {&quot;result&quot;:[{&quot;instruction&quot;:&quot;\n\n\u00a0 \u00a0&lt;\/head&gt;\n\n\u00a0 \u00a0\n\n\u00a0 \u00a0 \u00a0 
      <ul>
         \n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0
         <li>The Comprehensive R Archive Network&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0</li>
         <li>
            A network of global web servers storing identical, up-to-date, versions of<br \="" />code and documentation for R&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\n\n\u00a0 \u00a0 \u00a0 
            <p><br \="" /><strong>Download and Install R:&lt;\/strong&gt;&lt;\/p&gt;\n\n\u00a0 \u00a0 \u00a0 </strong></p>
            <ul>
               <strong>
                  \n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0
                  <li>Use the CRAN mirror nearest to you to download R setup at a faster<br \="" />speed. Go to <a href="\&quot;url\&quot;">\u00a0http:\/\/cran.r-project.org&lt;\/a&gt;&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0</a></li>
                  <li>
                     <a href="\&quot;url\&quot;">
                        Select one of the three download links according to your machine.&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\n\n\u00a0 \u00a0 \u00a0 <img src="\&quot;file:\/\/\/storage\/emulated\/0\/rreadyreckoner_images\/download-r.png\&quot;" alt="\&quot;downloadr\&quot;" width="\&quot;191\&quot;" height="\&quot;129\&quot;" \="" />\u00a0\n\n\u00a0 \u00a0 \u00a0 
                        <ul>
                           \n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0
                           <li>Run the R set up and follow the instructions of the installer.&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\n\n\u00a0 \u00a0&lt;\/body&gt;\n\n&lt;\/html&gt;\n\n&quot;}]} </li>
                        </ul>
                     </a>
                  </li>
               </strong>
            </ul>
         </li>
      </ul>
   </body>
</html>

有没有一种方法可以将 html 内容作为字符串检索,然后将其重构为纯 html 并将其显示在 webview 中。我是编程新手,因此感谢您提供任何帮助或建议。谢谢。

【问题讨论】:

  • @Jens 感谢您的编辑,您能否提供解决方案。
  • PS:锚内不能有 UL

标签: java android html mysql


【解决方案1】:

您可以使用 org.apache.commons.lang3.StringEscapeUtils.unescapeJava(text) 转义 unicode 字符,例如 \u00a0org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4(text) 转义 html 编码的字符,例如 &amp;quot;

StringEscapeUtils类可以从Apache Commons获取。

【讨论】:

    猜你喜欢
    • 2010-12-31
    • 2012-09-14
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2022-10-24
    • 2020-04-28
    • 1970-01-01
    相关资源
    最近更新 更多