Anumeha Prasad

+ Follow
since Feb 06, 2012
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anumeha Prasad

Thanks Bill and Paul.

Bill, the mentioned characters may be illegal for XML, but my problem was with characters such as 0xe, 0xf, etc.
What I found out is that there is a set of 32 control characters in ASCII which are not meant to be printed on screen, but only perform some special keyboard functions. You can find them here:

They're obsolete now and somehow coming into my XML. There are two solutions to it:
1. Remove them by pattern matching as mentioned in this thread. (best soln)
2. If you wanna keep them (just like me) then change your XML version to 1.1 and escape the characters as:

Here ch is the illegal character. After this you can unescape them using StringUtils unescapeNumericChar() method.

Hope this is useful to someone.

I'm not very sure about how these characters came into my XML. But we deal with different languages, so I'm afraid removing such characters could be a loss of data as they might be of relevance to other regions.

Do you know of some other parser that can parse such characters?


I'm using Transformer to convert XML into PDF. But the problem comes with some invalid characters like 0xf, 0xe, etc. Some exception prints like:

javax.xml.transform.TransformerException: An invalid
XML character (Unicode: 0xf) was found in the element content of the

Now, with the given solution, I'm able to get rid of these characters through pattern matching. But I don't want to lose these charactes but parse them somehow. Is there a way to do this? Please find below the code that I'm using:

File pdffile = new File(filePath);
// Setup output
out = new FileOutputStream(pdffile);

Fop fop = configureFop(true, out);
if (fop == null)
fop = configureFop(false, out);

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = templates.newTransformer();

transformer.setParameter("versionParam", "2.0");
Result res = new SAXResult(fop.getDefaultHandler());
Source source = new StreamSource( temp );

transformer.transform(source, res);

Here temp is the input XML file. Any help would be appreciated