Trying
Trying

Reputation: 14278

period symbol in xml causing issue

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?

Upvotes: 0

Views: 205

Answers (2)

Aniket Thakur
Aniket Thakur

Reputation: 68975

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

Upvotes: 0

Alex Fitzpatrick
Alex Fitzpatrick

Reputation: 644

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>

Upvotes: 1

Related Questions