Skip to Main Content

Java Programming

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 get all child elements from XML

967752Oct 11 2012 — edited Oct 15 2012
Hi
I have one xml i tried to parse that xml using dom parser and i need to get some child elements using java

<Group>
<NAME>ABC</NAME>
<Age>24</AgeC>
---------some data here......
<Group1>
<group1Category>
<NAME>ABCTest</NAME>
<age>27</Age>
----Some data here
<group1subcategory>
<subcategory>
<NAME>ABCDEF</NAME>
<age>28</Age>



my intention was
get group name (here ABC) i need all other name value from group1category ,group1 subcategory but pblm that
my xml contains any number of Group nodes...but only i want name contains ABC

i wriiten code like this
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlFile);
NodeList nodeList = document.getElementsByTagName("*");

for (int i = 0; i < nodeList.getLength(); i++)
{
Element element = (Element) nodeList.item(i);
}
what is next step i need to do..please help
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 12 2012
Added on Oct 11 2012
6 comments
1,487 views