URL url = new URL("http://www.site.com/1.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLHandler handler = new XMLHandler();
parser.parse(url.openStream(),handler);
Because 1.xml contains invalid XML characters, parser will throw exceptions, such as An invalid XML character (Unicode: 0x1d) was found in the CDATA section.
but if I read the 1.xml into a String and filter all invalid characters, string can’t be the argument of parser.parse() method.
what can I do ?
Looks like you can use
java.io.StringReaderto make aReaderfrom your string, then construct anorg.xml.sax.InputSourceusing theStringReader. There’s a version ofparse()that takes anInputSourceargument.