2 Replies Latest reply on Dec 10, 2008 8:45 AM by huhaihong

    How to convert the HTML into text

    huhaihong

      The code.


      mail.xhtml


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          >
      <head>
      </head>
      <body>
      {email.body}
      </body>
      </html>




      That is the problem:


      I get the {email.body} from the database, and suppose its value is "<p>huhaihong</p> <p>hhh</p>".
      
      And then I opened the mail.xhtml, the page showed "<p>huhaihong</p> <p>hhh</p>". 




      But I want it to show
      huhaihong
      hhh


      How should I do?
      I'm hoping someone can help me. Thanks.

        • 1. Re: How to convert the HTML into text
          mail.micke

          Hi


          Do you want to remove all html elements from the text?


          Or do you want want the text to not be escaped?


          If you want to remove all html tags all you need is some regular expression magic, or use a html parsing library (I'd go for regexp).


          If you just don't want the html to be escaped do this:


          <h:outputText value="#{email.body}" escape="false"/>
          



          Cheers,
          micke

          • 2. Re: How to convert the HTML into text
            huhaihong

            Mikael Andersson wrote on Dec 09, 2008 10:31:


            Hi

            Do you want to remove all html elements from the text?

            Or do you want want the text to not be escaped?

            If you want to remove all html tags all you need is some regular expression magic, or use a html parsing library (I'd go for regexp).

            If you just don't want the html to be escaped do this:

            <h:outputText value="#{email.body}" escape="false"/>
            



            Cheers,
            micke


            Thanks for your reply. I want to remove all html tag, however I also want the text between p tag can display on a new line.