I meant to say ...until you hit a corresponding ContentHandler.endElement(
Main Topics
Browse All TopicsUsing SAX parsing method is there any way by which we can get all the children of a particular node. For example, if i am having a xml like this
<a>
<b>
<c></c>
</b>
</a>
Using DOM parsing i can get all the child elements of <a> with getChildNodes(). But since SAX parsing is serial, i am not very sure how can i get the children of a particular element?
Thanks in advance
kgreddy
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi Yoren,
when StartElement() executes (ContentHandler.startEleme
is there any way by which i can get all the nodes recursively. If you have seen the parameters of start element, it contains only about attributes.
Thanks
You cant know if an element has child nodes or not. You have to store the current element somewhere and wait for more calls to the function with child nodes. You cannot do anything recursively with SAX, thats the very difference. I suggest you stick to DOM since it appears that your needs are essentially random. If you need to access an XML file rather serially or are interested in a small part only, only then you should go for SAX
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- split points between yoren and hardeepbsingh
Please leave any comments here within the
next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
girionis
Cleanup Volunteer
Business Accounts
Answer for Membership
by: yorenPosted on 2002-06-03 at 10:59:50ID: 7051742
With SAX you have to figure it out yourself. Add a check in ContentHandler.startElemen t() to see if it's the "a" node. If so, then you know that everything you get until you hit a corresponding Contenthandler.element() is part of that node.
Depending on your needs, you may have to create your own tree structure. If you have to do more than a few of these you might consider just sticking with DOM (or JDOM, etc.)