wood burning stoves 2.0
The moose likes XML and Related Technologies and the fly likes Encoding Special case characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Encoding Special case characters" Watch "Encoding Special case characters" New topic

Encoding Special case characters

Mike Miller

Joined: Mar 11, 2002
Posts: 5
Hi Guys,

Sorry if this is posted elsewhere, i've had a look and can't find it.

I'm creating a PDF via FOP, from user data so I need to include provisions for < > & etc...

I know i need to encode the characters into &#xxxx; format, and I can write a class to do this.

However is there a built in method somewhere, like the URLEncode.Encode? or should i use this and a regular expression to replace %84 with the format i need?

I'm using the bog standard UTF-8 encoding.

Any Help / comments would be appreciated.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
I used a whole lot of java.util.regex Pattern objects - precompiled as static variables.

with code like this....

I have no idea whether this is a fast way, but it worked for me.
Mike Miller

Joined: Mar 11, 2002
Posts: 5
Thanks for the help there... But I found a more elegant way to catch the issue.

Instead of translating the needed characters in code I've left it up to the processor by wrapping the text data in cdata tags.


This means I don't have to write code for each special case character and hasn't impacted the speed of which the PDF is created.

I agree. Here's the link: http://aspose.com/file-tools
subject: Encoding Special case characters
It's not a secret anymore!