Newbie question: how to look for a particular element in an XML document?

Discussion in 'XML' started by Sunitha Kumar, Jul 4, 2003.

  1. Hi,

    I'm just learning SAX, so I would appreciate advice with this problem I'm
    wrestling with.

    Here's the scenario:
    I've just parsed a xml document and stored the values I need in a class so I
    can print it out. But, I'm also looking for a particular data element within
    the elements, so I pass in the value I'm looking for, via the command line
    arguments.

    For example, within the element <year>, I'm looking for the value 1988.

    Should I:
    1. create another handler just to handle this case?
    (maybe subclass the class extending the DefaultHandler and override the
    endElement method?)

    2. I tried this approach, which failed miserably (it printed out everything
    anyway)
    if (year.equals(yearToFind))
    {
    System.out.print(article.toString);
    }
    else {
    //print out what I have without worrying about a particular year
    System.out.println(article.toString);
    }

    How can I do this? Any suggestions, comments, advice would be welcome!

    Thanks,
    Sunitha Kumar
    Sunitha Kumar, Jul 4, 2003
    #1
    1. Advertising

  2. Never mind, I got it.
    "Sunitha Kumar" <> wrote in message
    news:be39cp$ea4$...
    > Hi,
    >
    > I'm just learning SAX, so I would appreciate advice with this problem I'm
    > wrestling with.
    >
    > Here's the scenario:
    > I've just parsed a xml document and stored the values I need in a class so

    I
    > can print it out. But, I'm also looking for a particular data element

    within
    > the elements, so I pass in the value I'm looking for, via the command line
    > arguments.
    >
    > For example, within the element <year>, I'm looking for the value 1988.
    >
    > Should I:
    > 1. create another handler just to handle this case?
    > (maybe subclass the class extending the DefaultHandler and override the
    > endElement method?)
    >
    > 2. I tried this approach, which failed miserably (it printed out

    everything
    > anyway)
    > if (year.equals(yearToFind))
    > {
    > System.out.print(article.toString);
    > }
    > else {
    > //print out what I have without worrying about a particular year
    > System.out.println(article.toString);
    > }
    >
    > How can I do this? Any suggestions, comments, advice would be welcome!
    >
    > Thanks,
    > Sunitha Kumar
    >
    >
    Sunitha Kumar, Jul 4, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia
    Replies:
    0
    Views:
    366
    Luis Esteban Valencia
    Jun 20, 2005
  2. Tony Prichard
    Replies:
    0
    Views:
    718
    Tony Prichard
    Dec 12, 2003
  3. inhahe
    Replies:
    3
    Views:
    2,325
    Diez B. Roggisch
    Jan 28, 2005
  4. HANM
    Replies:
    2
    Views:
    698
    Joseph Kesselman
    Jan 29, 2008
  5. mick verdu
    Replies:
    10
    Views:
    118
    Peter Otten
    Jan 27, 2014
Loading...

Share This Page