Saturday, December 19, 2009

Re: [android-developers] Re: parsing a *string* of XML with SAX.

Thanks Mark, I've just given that a try. I still don't get any calls to my startElement method, but there is a new warning which may be a clue:

12-19 17:14:24.241: INFO/NWXML(1852): Trying to parse: *snip*
12-19 17:14:24.241: WARN/ExpatReader(1852): DTD handlers aren't supported.

DTD handlers aren't supported. Know what this means?

2009/12/19 Mark Murphy <mmurphy@commonsware.com>
redders wrote:
> I appreciate the reply, but I selected the SAX method because of its
> efficiency advantages, so I'd really like to understand why my code
> isn't working.

I don't use XMLReader and I have no problems with SAX on Android, such
as this one parsing a XML payload from a REST request:

BufferedReader in=new BufferedReader(new
InputStreamReader(url.openStream()));
SAXParserFactory f=SAXParserFactory.newInstance();
SAXParser p=f.newSAXParser();
SearchParser parser=new SearchParser(null);
p.parse(new InputSource(in), parser);

(where SearchParser is a DefaultHandler subclass)

In your case, this would look like:

SAXParserFactory f=SAXParserFactory.newInstance();
SAXParser p=f.newSAXParser();
StringReader sr = new StringReader(xmlMessage);
InputSource is = new InputSource(sr);
p.parse(is, this);

Try something like that and see if it helps.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 1.0 In Print!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate