While read a xml getting org.xml.sax.SAXParseException the parser exception when parsing the xml. i check text that create this Exception nothing special character found there. but while dBuilder.parse() method parse xml throw exception .
log4j:WARN File option not set for appender [file]. log4j:WARN Are you using FileAppender instead of ConsoleAppender? [Fatal Error] employeeInfo.xml:45:35: An invalid XML character (Unicode: 0x13) was found in the element content of the document. Exception in thread "main" org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x13) was found in the element content of the document. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180) at javastoreroom.ReadXML.main(ReadXMLFile.java:33)
Spending a lots of hour while (open xml in OpenOffice find the reason like Name :Arun but when check in OpenOffice it's look like Aru#n content some junk character) finally get solution first read all xml content using BufferedReader and do this :-
String lineReader =" "; while((lineReader = bufferedReader.readLine()) != null){ lineReader = lineReader.replaceAll("[^\\x20-\\x7e]", ""); buffer.append(l); }
Now create a temporary xml file and write buffer all content. Then read temp.xml now everything goes very well.Check it here valid or invalid character in xml
Hope this will help you :)
No comments:
Post a Comment