java1977
java1977

Reputation: 398

XML parsing error

I am getting org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x12) was found in the element content of the document. error on the client side. Can someone tell what is the regular expression using java.util.regex.Pattern to replace such characters so that I can exclude in the server side.

tried..

Pattern PATTERN = Pattern.compile("\0012");

but didn't work

Upvotes: 0

Views: 147

Answers (2)

Ed Staub
Ed Staub

Reputation: 15700

When you need to look for some literal string with stuff in it that the regex parser is likely to have trouble with, use Pattern.quote() around the literal.

Also, you're using an octal encoding, not a unicode one - you forgot the u after \.

In this case:

Pattern PATTERN = Pattern.compile(Pattern.quote("\u0012"));

Note: I haven't tried this particular case!

Upvotes: 0

keshlam
keshlam

Reputation: 8058

Most "control characters" (<32 ASCII) are not legal in XML 1.0. Some of them are legal in XML 1.1. If your users expect them to be supported, you may want to make sure you're using a parser which can handle the newer Recommendation.

Upvotes: 1

Related Questions