use xmlpullparser much easier

On Fri, Dec 18, 2009 at 5:50 PM, redders <[email protected]> wrote:

> Okay, so I know that the parse() method takes an inputsource, and
> normally it'd be better to parse the xml at the source (where it's a
> stream), but in this case I want to be parsing it on a different
> thread to the thread it's being received on.
>
> My question is basically a "why won't this work" question...
> As far as I can tell, the startElement method is never being called
> (no "startelement" entries in logcat after "trying to parse..")
> .. any help appreciated.
>
> Here's the code.
>
> public class NWCommsXMLParser extends DefaultHandler{
>        public void startElement(String uri, String name, String qName,
> Attributes atts){
>                Log.i("NWXML","startelement: " + uri + "." + name + "." +
> qName +
> "/" + atts.toString());
>        }
>        public void endElement(String uri, String name, String qName){
>
>        }
>        public void characters(char ch[], int start, int length) {
>
>        }
>        public void parseMessage(String xmlMessage){
>
>                Log.i("NWXML","Trying to parse: " + xmlMessage);
>                try{
>                        SAXParserFactory parseFactory =
> SAXParserFactory.newInstance();
>                        SAXParser parser = parseFactory.newSAXParser();
>                        XMLReader xmlReader = parser.getXMLReader();
>                        xmlReader.setContentHandler(this);
>                        StringReader sr = new StringReader(xmlMessage);
>                        InputSource is = new InputSource(sr);
>                        xmlReader.parse(is);
>                }
>                catch(Exception e){
>                        Log.e("NanoWarsXML","SAX error:" + e);
>                }
>        }
> }
>
>
> Logcat line before the try{} :
> 12-19 01:31:38.763: INFO/NWXML(3218):
> Trying to parse:
>  <NWC><NWR type="dat" id="1" ><PSL>123447</PSL><PSLg>87645</PSLg></
> NWR></NWC>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to