0

i have a xml like below:

<expectedJson> { "x":"give him $12&#46;25" } </expectedJson>

What i am doing is: am comparing the json embeded with the actual json. But after parsing this xml, &#46; is getting converted to . i.e. period.

I want it to be interpreted as &#46; not as .. can anybody help on this?

Trying
  • 14,004
  • 9
  • 70
  • 110

2 Answers2

1

The ampersand needs to be escaped to avoid it being treated as the start of an entity. See this to escape the ampersand.

<expectedJson>
{
"x":"give him $12&#038;#46;25"
}
</expectedJson>

or

<expectedJson>
{
"x":"give him $12&amp;#46;25"
}
</expectedJson>
Community
  • 1
  • 1
Alex Fitzpatrick
  • 643
  • 5
  • 10
0

XML has special characters like & that have a special meaning in XML. So you cannot use it directly as data. You need to escape it. For Eg. & should become &amp; after escaping it. For more details on handling special characters in XML, you can refer to my personal blog post -> Escaping special characters of XML in Java

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289