Analizar Amazon ItemSearch usando SAX

I'm having trouble parsing the XML output from an Amazon product search using a SAX parser. I'm trying to only retrieve the titles and links from the XML. When I step through the code, I never enter any of the listeners.

Esto es lo que tengo hasta ahora:

 public class AmazonFeedParser 
    public static List<AmazonItem> parse(final String url)
        final AmazonItem currentItem = new AmazonItem();
        final List<AmazonItem> returnItems = new ArrayList<AmazonItem>();

        final RootElement root = new RootElement("ItemSearchResponse");
        final Element items = root.getChild("Items");
        final Element item = items.getChild("Item");

        item.getChild("DetailPageURL").setEndTextElementListener(new EndTextElementListener()
            public void end(final String body) {

        final Element attributes = item.getChild("ItemAttributes");

        attributes.getChild("Title").setEndTextElementListener(new EndTextElementListener()
            public void end(final String body) {

        item.setEndElementListener(new EndElementListener()
            public void end() {

            final InputStream stream = new URL(url).openConnection().getInputStream();

            Xml.parse(stream, Xml.Encoding.UTF_8, root.getContentHandler());
        catch (Exception e) 

        return returnItems;

This is the XML I'm try to parse:

            <Description>Technical Details</Description>
            <Manufacturer>Taylor Thermometers</Manufacturer>
            <Title>Taylor 1470 Digital Cooking Thermometer/Timer</Title>

EDIT: If it helps anyone I needed to add the Amazon namespace to the parser code, eg:

    final RootElement root = new RootElement("", "ItemSearchResponse");
    final Element items = root.getChild("", "Items");
    final Element item = items.getChild("", "Item");

    item.getChild("", "DetailPageURL").setEndTextElementListener(new EndTextElementListener()
        public void end(final String body) {

preguntado el 30 de enero de 12 a las 19:01

uh, why did someone untag this from android? It's using Android-specific SAX helpers. -

oh, btw, tested that code on 2.3 and the listeners were called with the expected values for DetailPageURL and Title. -

really? I must be missing something obvious. I'll try again. -

yup, i replaced your AmazonItem with System.out.println() ofc and just dumped the XML as a stream into it. -

I know what the problem is, I'm getting an exception thrown in the try/catch, but it's good to know the code works. Thanks for the response. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.