Why using InputSource fixes SAX parser when file contains special UTF-8 characters

ahmedbekhit

New Member
I'm looking to get an explanation on why my SAX parser fails when some special UTF-8 characters are inside my XML file.To parse the XML file I use \[code\]Document doc = builder.parse(inputSource);\[/code\]However when I use an \[code\]inputSource\[/code\] it works fine:\[code\]DocumentBuilder builder = factory.newDocumentBuilder();InputStream in = new FileInputStream(file);InputSource inputSource = new InputSource(new InputStreamReader(in));Document doc = builder.parse(inputSource);\[/code\]I don't quite understand why the latter works. I've seen example of it being used but there isn't an explanation on why it works.Does the second parse a string rather than a file, therefore the encoding will be UTF-8?
 
Back
Top