jo_atman Posted October 12, 2006 Share Posted October 12, 2006 Sorry,another question for the admins and fathers of JasperReports: If i do the replaceAll() for special characters (like &) in the jrxml, it works. If i do it in the getFieldValue() in my DataSource (so i can handle it generically for all my data), it somehow seems to get converted to a plain & again, and i get a SAXParseException.Any idea how i can get around this?Thanks,Nilesh Link to comment Share on other sites More sharing options...
Teodor Danciu Posted October 12, 2006 Share Posted October 12, 2006 Hi, Ampersand characters coming from the data source and ampersand characters present in JRXML are different things.Note that JRXML is going to be parsed and if you escape ampersands, they will be consumed at first XML parsing passage.Ampersands in the data source or in parameters do not matter because you never parse that as XML, do you?So why should you escape them? Then there is a twist to it. What if you need ampersands in styled text elements? Well, if present in JRXML as static styled text, you need to escape them twice, because the first escape is consumed by parsing JRXML and the second gets consumed by parsing styled text (which is itself XML).Ampersands coming from data in styled text, need to be escaped only once, as the get consumed only when parsing styled text as XML. Check the styled text sample for details. I hope this helps.TeodorPost edited by: teodord, at: 2006/10/12 11:39 Link to comment Share on other sites More sharing options...
jo_atman Posted October 12, 2006 Author Share Posted October 12, 2006 Teodor,Thanks a lot. That helped me fix the problem.Since we determine the font dynamically, in the datasource, we wrap the actual value with a <style> element. so, as you said, the & in this styled value needed a double escaping. So adding a double escape of the ampersand in the getFieldValue() did the trick.Thanks again,Nilesh Link to comment Share on other sites More sharing options...
tomatg Posted October 21, 2006 Share Posted October 21, 2006 How do we escape the ampersand twice? & a m p ; & a m p ;? Thanks,Tom Link to comment Share on other sites More sharing options...
jo_atman Posted October 21, 2006 Author Share Posted October 21, 2006 So you escape the first one by saying& a m p;and then you escape the ampersand in that escaped ampersand:( & a m p ; ) a m p ;(parentheses are just for illustration) thus:& a m p ; a m p ; :)Post edited by: jo_atman, at: 2006/10/20 21:18 Link to comment Share on other sites More sharing options...
tomatg Posted October 21, 2006 Share Posted October 21, 2006 Thanks a bunch you saved the day!I owe you a malted beverage.Cheers! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now