Results 1 to 8 of 8
  1. #1
    newbieal is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default adding <br> html tag to string

    I've a string that contains text as well as HTML code, however it interprets the html code as text, how do i need to adjust my code?

    string astring = "text" + "<br>" + "text";

    The <br> is interpreted as: &lt;br&gt

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default

    it interprets the html code
    What is the "it"? What program is it? How is it getting the String?
    Is this a java programming question?
    Or an HTML coding question?

  3. #3
    newbieal is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    It's a java program, let's say aprogram.java. It contains a String variable and I'm assigning text and the html tag <br> to that string.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default

    is interpreted as: &lt;br&gt
    What program does that?
    Show me the java code with a println() that will output the HTML encodings vs the < & >.

    I think you are feeding a string to a browser or server and it is converting the <>, not the java code.

  5. #5
    newbieal is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    The string is used to update the HTML. Once the HTML is updated, it shows &lt;br&gt instead of <br>

    I'm just trying to figure out what I need to do so that it doesn't change <br> and sees it as a true HTML tag.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default

    You'll have to describe the data flow a bit more for any help. Where does the String with the <>s go from the java program?
    What other software is involved that converts it?

  7. #7
    newbieal is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default java dom

    I use java dom and xml serializer to update the html doc. I did a system.out.println on the text of the node the string is applied to and the tag is rendered correctly there, so it must be the xml serializer that changes it. any ideas on how to prevent that from happening?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default

    You'll have to read the API doc for the methods and classes to see how to "escape" the <>, since XML uses those characters as delimiters you'll have to tell the software it's not XML.
    No ideas here.

Similar Threads

  1. How can I include a html file in html textarea?
    By surya_dks in forum New To Java
    Replies: 2
    Last Post: 10-04-2008, 07:20 AM
  2. How to make Java see a string as html
    By matpj in forum Java Applets
    Replies: 4
    Last Post: 09-26-2008, 03:40 AM
  3. Replies: 0
    Last Post: 11-20-2007, 04:59 PM
  4. Replies: 1
    Last Post: 08-07-2007, 07:29 AM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •