0

My xml data = <Item "/api/items/4000000002011"><ItemID>4000000002011</ItemID><Name>Sample Item1</Name><Description>Sample Description</Description><Rate>34.00</Rate><Tax1Name>PST</Tax1Name><Tax1Percentage>8</Tax1Percentage><Tax2Name/><Tax2Percentage/></Item>

Html output=<Item uri="/api/items/4000000002011"> <ItemID>4000000002011</ItemID><Name>Sample Item1</Name><Description>Sample Description</Description><Rate>34.00</Rate><Tax1Name>PST</Tax1Name><Tax1Percentage>8</Tax1Percentage><Tax2Name/><Tax2Percentage/></Item>

I want to html output.How do I?

<Item "/api/items/4000000002011">
 <ItemID>4000000002011</ItemID>
 <Name>Sample Item1</Name>
 <Description>Sample Description</Description>
 <Rate>34.00</Rate>
 <Tax1Name>PST</Tax1Name>
 <Tax1Percentage>8</Tax1Percentage>
 <Tax2Name/>
 <Tax2Percentage/>
</Item>
ujava
  • 1,846
  • 5
  • 20
  • 24

3 Answers3

1

Just output the raw data as is, with &lt; and &gt;. Don't unescape before rendering.

Axel Fontaine
  • 34,542
  • 16
  • 106
  • 137
0

Recommended method for escaping HTML in Java

Are you looking for something like this?

Community
  • 1
  • 1
Malte Köhrer
  • 1,577
  • 10
  • 19
0

One option could be to use the StringEscapeUtils.escapeXML method in the Apache Commons Lang API.

Alternatively, simply escape the XML entities - i.e. replace

>     <     "     &     '

with

&gt; &lt; &quot; &amp; &apos;
AbdullahC
  • 6,649
  • 3
  • 27
  • 43