Hey Brad and Charlie,
I thought I'd submit my source code for everyone's reference. At this
point I'm very confident this is a bug. If it isn't I clearly don't
know nearly as much about XML and text encoding as I think I do :-)

The XML doc being passed in looks something like this:

<?xml version="1.0" encoding="utf-8" ?>
<Categories>
   <cat>
      <id>{282CE5E0-50C0-46B7-8996-176A3F12808D}</id>
      <catName>Category & Name</catName>
   </cat>
   <cat>
      ...
   </cat>
   ...
</Categories>

Note this is coming from a .Net web service and and all characters are
encoded.

The code to parse it is here:
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = null;
                try {
                        sp = spf.newSAXParser();
                } catch (ParserConfigurationException e1) {
                        e1.printStackTrace();
                } catch (SAXException e1) {
                        e1.printStackTrace();
                }
                XMLReader xr = null;
                try {
                        xr = sp.getXMLReader();
                } catch (SAXException e1) {
                        e1.printStackTrace();
                }
                CatListResponse catListHandler = new CatListResponse(ctx);
                xr.setContentHandler(catListHandler);

                Reader rd = null;
                try {
                        rd = new
StringReader(EntityUtils.toString(httpResponse.getEntity()));
                } catch (ParseException e1) {
                        e1.printStackTrace();
                } catch (IOException e1) {
                        e1.printStackTrace();
                }

                try {
                        xr.parse(new InputSource(rd));
                } catch (IOException e) {
                        e.printStackTrace();
                } catch (SAXException e) {
                        e.printStackTrace();
                }

And the handler code is here:

public class appCatListResponse extends DefaultHandler{

    private boolean in_cat = false;
    private boolean in_id = false;
    private boolean in_catName = false;
    private String id;
    private String catName;
    private Context ctx;
    private AppCatListLA lla = new AppCatListLA(ctx);

    public appCatListResponse(Context _ctx) {
        ctx = _ctx;
    }
    public CatListLA getParsedData() {
        return this.lla;
    }

    @Override
    public void startDocument() throws SAXException {
         this.lla = new CatListLA(ctx);
    }

    @Override
    public void endDocument() throws SAXException {
        // Nothing to do
    }

    @Override
    public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
        if (localName.equals("cat")) {
                in_cat = true;
        }
        else if (localName.equals("id"))
        {
                in_cat = false;
                in_id = true;
        }
        else if (localName.equals("catName"))
        {
                in_cat = false;
                in_catName = true;
        }
    }

    @Override
    public void endElement(String namespaceURI, String localName,
String qName)
    throws SAXException {
        if (localName.equals("cat")) {
                in_cat = false;
        }
        else if (localName.equals("id"))
        {
                in_id = false;
        }
        else if (localName.equals("catName"))
        {
                in_catName = false;
        }
    }

    @Override
    public void characters(char ch[], int start, int length) {
        if(this.in_cat){
                id = null;
                catName = null;
        }
        else if (in_id)
        {
                id = new String(ch, start, length);
        }
        else if (in_catName)
        {
                catName = new String(ch, start, length);
                id = null;
                catName = null;
        }
    }
}


Charlie, you hit it on the money though, why has this behavior changed
between SDK versions without documentation? Again it leads me to
believe this is a bug...
--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to