Reputation: 267140
My xml has text inside an element that looks like:
<node>#<abc123></node>
So in my junit test I am doing an assertEqual it fails because the value I get from the xml looks like:
<#abc123>
Does calling toString on a Object decode it? Or going from a StringBuffer to a String?
Upvotes: 1
Views: 102
Reputation: 80623
If you are doing an assert on the raw XMl string #<abc123>
it is going to fail, because the following sequences are XML specific encodings that get translated away by your parser:
The reason for the encodings in the first place is pretty obvious - the '<' and '>' characters have special meaning in XML, so to include them literally in your document would cause problems for the parser.
What you need to do is assert on the String that would be outputted by your XML parser, which is '<#abc123>'
.
Upvotes: 4
Reputation: 2111
my guess would be that your xml framework unescapes the text in the moment you call getText() on the node. Maybe you have access the node content in a different way to get the raw content.
Upvotes: 0
Reputation: 62234
This depends on the implementation of the toString method. toString gives a string representation of the object, in your case it converts <
to <.
Upvotes: 0
Reputation: 1828
this might help you,
look for escapeHtml
in
StringEscapeUtils
http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/StringEscapeUtils.html
Upvotes: 0