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 & &amp;, 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 '&' '&amp;' ruin special meaning intended. there solution take full xml document , 'fix' '&' become '&amp;', intended? safe globally replace ' & ' ' &amp; ' (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

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -