<p>I have an XML file that's the output from a database.  I'm using the Java SAX parser to parse the XML and output it in a different format.  The XML contains some invalid characters and the parser is throwing errors like 'Invalid Unicode character (0x5)'</p>

<p>Is there a good way to strip all these characters out besides pre-processing the file line-by-line and replacing them?  So far I've run into 3 different invalid characters (0x5, 0x6 and 0x7).  It's a ~4gb database dump and we're going to be processing it a bunch of times, so having to wait an extra 30 minutes each time we get a new dump to run a pre-processor on it is going to be a pain, and this isn't the first time I've run into this issue.</p>

I haven't used this personally but Atlassian made a command line XML cleaner that may suit your needs (it was made mainly for JIRA but XML is XML):
Download
atlassian-xml-cleaner-0.1.jar
Open a DOS console or shell, and locate the XML or ZIP backup file on your computer, here assumed to be called data.xml
Run:
   java -jar atlassian-xml-cleaner-0.1.jar data.xml > data-clean.xml
This will write a copy of data.xml to data-clean.xml, with invalid characters removed.