Android SAX xml not well-formed

Put your problem here if it does not fit any of the other categories.

Android SAX xml not well-formed

Postby caldis » Fri Jan 09, 2009 2:32 pm

Hi all,

I am using sax to parse a local configuration file (.xml) and get the following error:

Code: Select all
01-09 13:54:18.169: WARN/System.err(1329): org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: not well-formed (invalid token)


This is the corresponding xml file:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0"?>
  2. <config>
  3. asdf
  4. </config>
  5.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


There do not seem to be any encoding issues. (But I wouldn't really know how to detect them.)

This is the code used to load the xml file:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. SAXParserFactory spf = SAXParserFactory.newInstance();
  2. SAXParser sp = spf.newSAXParser();
  3. XMLReader xr = sp.getXMLReader();
  4. xr.setContentHandler(this);
  5. xr.parse(new InputSource(context.getResources().openRawResource(R.xml.config1)));
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I tried using getResources().getString(R.xml.config1) but that resulted in this error:

Code: Select all
01-09 14:00:51.440: WARN/System.err(1372): java.io.IOException: Couldn't open res/xml/config1.xml


All suggestions are welcome. Thanks
caldis
Freshman
Freshman
 
Posts: 7
Joined: Mon Dec 08, 2008 1:07 pm

Top

Postby mortefer » Sat Jan 10, 2009 10:59 pm

Question remains open - i've just spotted the same issue. Please guys, share the info of how you read xml files?

tnx
mortefer
Experienced Developer
Experienced Developer
 
Posts: 54
Joined: Sat Dec 20, 2008 11:24 am

Postby mortefer » Thu Jan 15, 2009 12:46 am

Found out an interesting stuff - when moving xml file from xml folder to raw, everything works smoothly. I guess that's why the function is called openRawResource :D.
Anyways i think that android adds some stuff to the files stored in non raw folder. But this is just a thinking aloud.
mortefer
Experienced Developer
Experienced Developer
 
Posts: 54
Joined: Sat Dec 20, 2008 11:24 am

Postby caldis » Thu Jan 15, 2009 1:34 pm

Interesting, thanks.
We have decided to go with the Xstream-Parser. It parses right in to an object.

We'll see how that goes.
caldis
Freshman
Freshman
 
Posts: 7
Joined: Mon Dec 08, 2008 1:07 pm

Postby caldis » Thu Jan 22, 2009 11:13 am

Using XStream and XPP3 worked almost like a charm. I downloaded the latest version from the svn and compiled it with eclipse included the xstream*.jar and xpp*.jar in my project and it worked just fine.
XStream and XPP3 use about 500 kb combined.

I recommend using this solution. Works good and feels fast.
caldis
Freshman
Freshman
 
Posts: 7
Joined: Mon Dec 08, 2008 1:07 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests