Avatar of AssetFX
AssetFX
Flag for Australia

asked on 

Parsing FileInputStream for xml on Android

Hi,
I am running Android 4.0 API Level 14

This is my xml file
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<local_root />

Open in new window

This is my java
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
	
fileRead = new FileInputStream(localXMLfile);
Document doc = db.parse(fileRead);

doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("local_root");

Open in new window

It is throwing the following exception
org.xml.sax.SAXParseException: Unexpected token (position:TEXT ?xml version='1....@2:1 in java.io.InputStreamReader@413b7ab8)
on this line:
Document doc = db.parse(fileRead);

Open in new window


I thought it might be something to do with the UTF-8 encoding.

Any help would be greatly appreciated!
AndroidJavaXML

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon