tags:

views:

166

answers:

1

Hi,

I am having trouble parsing self closing XML tags using SAX. I am trying to extract the link tag from the Google Base API.I am having reasonable success in parsing regular tags.

Here is a snippet of the xml

<entry>
  <id>http://www.google.com/base/feeds/snippets/15802191394735287303&lt;/id&gt;
  <published>2010-04-05T11:00:00.000Z</published>
  <updated>2010-04-24T19:00:07.000Z</updated>
  <category scheme='http://base.google.com/categories/itemtypes' term='Products'/>
  <title type='text'>En-el1 Li-ion Battery+charger For Nikon Digital Camera</title>
  <link rel='alternate' type='text/html' href='http://rover.ebay.com/rover/1/711-67261-24966-0/2?ipn=psmain&amp;amp;icep_vectorid=263602&amp;amp;kwid=1&amp;amp;mtid=691&amp;amp;crlp=1_263602&amp;amp;icep_item_id=170468125748&amp;amp;itemid=170468125748'/&gt;
.
.

and so on

I can parse the updates and published tags, but not the link and category tag.

Here is my startElement and endElement overrides

public void startElement(String uri, String localName, String qName,
     Attributes attributes) throws SAXException {
     if (qName.equals("title") && xmlTags.peek().equals("entry")) {

     insideEntryTitle = true;

   } 
   xmlTags.push(qName);

 }

public void endElement(String uri, String localName, String qName)
     throws SAXException {
   // If a "title" element is closed, we start a new line, to prepare
   // printing the new title.

   xmlTags.pop();
   if (insideEntryTitle) {
     insideEntryTitle = false;
  System.out.println();
   }
 }

declaration for xmltags..

private Stack<String> xmlTags = new Stack<String>(); 

Any help guys?

this is my first post here.. I hope I have followed posting rules! thanks a ton guys..

A: 

My apologies! endElement gets called. The following does not

public void characters(char[] ch, int start, int length) throws SAXException

{ if (insideEntryTitle) { String url= new String(ch, start, length);

          System.out.println("url="+title);
        i++;


      }

    }
sandesh