Avatar of AssetFX
Flag for Australia

asked on 

Parsing FileInputStream for xml on Android

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);

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!

Avatar of undefined
Last Comment

8/22/2022 - Mon