0

Jibx gives error if XML contains special characters like &. I need to correctly bind text in attributes to corresponding java property. I cannot use style="cdata" as its an attribute not child tag. my XML contains -

<Comments>
 <Comment Name="Res_Notes" Text="BED PREFERENCE: http://www.abcd.com?a=b&c=d"/>
</Comments>

How can I handle it? The Text attribute contains URL (with get parameters seperated by ampersand) so I cannot replace & with &amp; otherwise the URL will become invalid.

Is there any way to handle this at JibX level??

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
sameer59
  • 97
  • 11
  • That's simply not a valid XML element. It's not jibx-specific - it's plain invalid XML. Where did you get it from, and can you fix that source? – Jon Skeet Dec 03 '12 at 07:28
  • XML doesn't contain special characters like &. If it does, it's not XML. No XML-based tool will handle such input. – Michael Kay Dec 03 '12 at 10:01

1 Answers1

0

Sameer, This is invalid XML. If you use JiBX, you shouldn't have to worry about this. If you set your JiBX object to a string, for example:

name = "BED PREFERENCE: http://www.abcd.com?a=b&c=d";

JiBX will automatically convert this to valid XML when you marshal your object:

<Comments>
<Comment Name="Res_Notes" Text="BED PREFERENCE: http://www.abcd.com?a=b&amp;c=d"/>
</Comments>

JiBX will also automatically convert the XML back to a regular java string when it unmarshals the XML.

I hope this helps.

Don Corley
JiBX contributor

Don Corley
  • 496
  • 2
  • 7