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

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

Post by Sunitha Kuma » Sat, 05 Jul 2003 16:10:42



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

 
 
 

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

Post by Sunitha Kuma » Sun, 06 Jul 2003 07:56:39


Never mind, I got it.

Quote:> 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


 
 
 

1. Particular data in a particular table column

If I have an XML file similar to the following :

<yes>
<in>
   <oi rfd="7" monkeys="something something"/>
   <oi rfd="7" monkeys="something something"/>
   <oi rfd="8" monkeys="something something"/>
   <oi rfd="8" monkeys="something something"/>
   <oi rfd="9" monkeys="something something"/>
   <oi rfd="10" monkeys="something something"/>
   <oi rfd="11" monkeys="something something"/>
</in>
</yes>

If I have a table with say 11 columbs, how do I put rfd=x into it's
designated column?  ie. rfd="11" goes into column 11, or into column
6.

Much thanks
RelaxoRy

2. Connectionism

3. Newbie question: looking for a good XML editor for Macintosh...

4. ORB Drive

5. How to parse a particular element only once using xalan?

6. DB-EXPERT

7. determining if a document object contains a particular node object

8. Shipping software from U.S.A. to Canada.

9. Finding the size of the largest subset of elements for a particular attribute value - XSLT

10. Newbie question, using Xerces for reading/writing/parsing XML files, how to delete element?

11. newbie question posting xml documents on the web

12. Newbie question - viewing an xml document with Internet Explorer

13. Newbie question: Alphabetize an XML document?