Trouble parsing self closing XML tags using SAX parser

Posted by sandesh on Stack Overflow See other posts from Stack Overflow or by sandesh
Published on 2010-04-25T07:46:28Z Indexed on 2010/04/25 7:53 UTC
Read the original article Hit count: 211

Filed under:
|

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</id>
  <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;icep_vectorid=263602&amp;kwid=1&amp;mtid=691&amp;crlp=1_263602&amp;icep_item_id=170468125748&amp;itemid=170468125748'/>
.
.

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..

© Stack Overflow or respective owner

Related posts about java

Related posts about sax