Results 1 to 3 of 3
  1. #1
    iamhappy is offline Member
    Join Date
    Feb 2008
    Rep Power

    Default Html tags within XML- need help

    i am reading a database table and creating an XML. some of the values of the variables have html tags like <A href="">yahoo</A> . but after generating the XML i see the above value as
    &lt;BR&gt;&lt;A href=""&gt;yahoo&lt;/A&gt;&lt;BR&gt;

    is there any way that it can represent the actual html tags

  2. #2
    jelly's Avatar
    jelly is offline Member
    Join Date
    Jan 2008
    Somerset, UK
    Rep Power


    The reason that the conversion when the XML is written is is that the values you are trying to store are considered to be parsed data, i.e data that is the middle of a start and end tag, like the word FRED in the following

    Java Code:
    data stored in this way is looked at and parsed by XML parsers hence any '<' or '>' characters would cause problems ( the parser would not know whether a tag was starting or whether this was data. One way round this is to convert the < and > characters ( and some others ) to what are known as entities &lt; and &gt; which represent the less than and greater than symbols. This is what you seeing. Another way round the problem is to tell the parser _not_ to look at the data - then you can put there what you like, you do this by creating CDATA blocks which would look like the following for your example of an <a> tag

    Java Code:
            <A href="">yahoo</A>
    -- Hope that helps

  3. #3
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    London, UK
    Rep Power


    How about using String replace?

    Java Code:
    if (yourString.contains("&lt;")){
    yourString = yourString.replaceAll("&lt;","<");
    You could read in the data and replace the characters then re-write out the .xml and everything will be correctly formatted.

Similar Threads

  1. HTML tags for Struts
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-27-2007, 09:58 AM
  2. Help with Tags JSP
    By Marcus in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-04-2007, 02:53 PM
  3. How to parse HTML tags
    By Ada in forum Advanced Java
    Replies: 1
    Last Post: 05-31-2007, 09:42 PM

Posting Permissions

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