Jump to content
We've recently updated our Privacy Statement, available here ×

Sorry, Teodor: printing &


jo_atman

Recommended Posts

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

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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.

Teodor

Post edited by: teodord, at: 2006/10/12 11:39

Link to comment
Share on other sites

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

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...