Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to get only direct child node by tag name

843834Feb 20 2006 — edited Feb 20 2006
Hi,

I am using the method

getElementsByTagName("")....

This works except the problem is my XML schema/file has some recursive tags,

I have a <question> element which can have an <answer> or another <question>.

When parsing the XML file I want to be able to get a list of sub questions for a given question, but only if it is a direct child of that question.

So if i have:
<question>
  <text>q1</text>
  <question>
    <text>q2</text>
    <question>
      <text>q3</text>
    </question>
  </question>
</question>
If I'm dealing with the "q1" question I want only "q2" but not "q3". Whereas getElementsByTagName will take both q2 and q3. How can I achieve this.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 20 2006
Added on Feb 20 2006
2 comments
883 views