Achaius
Achaius

Reputation: 6124

How to replace invalid characters using java

Invalid XML: Error on line 190: An invalid XML character (Unicode: 0x10) was found in the CDATA section.

I get this error while parsing an XML file, I used String.replaceAll to replace this character but my regex pattern seems to be incorrect.

The following is a different string, but it just gives me back the original string. How should I do it?

str = str.replaceAll("\\^p", "");

Upvotes: 0

Views: 2862

Answers (2)

zx81
zx81

Reputation: 41848

Use this:

String replaced = your_original_string.replaceAll("\\x10", "");
  1. The xdd... is the Java syntax to match a single unicode character
  2. Your error said Unicode: 0x10

Upvotes: 5

Joop Eggen
Joop Eggen

Reputation: 109613

str = str.replace("\u0010", "");

Or maybe you need a space

str = str.replace("\u0010", " ");

Upvotes: 1

Related Questions