java - How can I make my xml safe for parsing (when it has & character in it)? -
i've been given xml string need put through parser. complaining because of illegal xml character. simplified example:
<somexml>this & that</somexml>
i know solution replace &
&
, i'm not generating xml , therefore have no control on values.
a simple string replace not right way to since '&' has special meaning in xml , global replace of '&' '&' ruin special meaning intended. there solution take full xml document , 'fix' '&' become '&', intended? safe globally replace ' & ' ' & ' (note spaces on either side)?
i think interesting question, because it's situation may happen in real-life. although believe right thing asking xml provider fix xml , make valid, thought 1 option trying lenient parser. did search , found blog post talking same problem, , suggesting same solution think of. may try jsoup. let me repeat think not best thing do: should ask xml provider fix it.
Comments
Post a Comment