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 do I retreive the child node names list from XML

843834Feb 18 2008 — edited Feb 19 2008
Hi,

I wanted to get Child node names from the below XML file. I am using DOM parser for reading the XML file in my program. Please help me. Just I need the child node name of employee node like firstname and Lastname.
<company>
	<employee>
		<firstname>priya</firstname>
		<lastname>mantra</lastname>
	</employee>	
</company>
NodeList nodeLst = doc.getElementsByTagName("employee");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element) fstNode;
NodeList fstNmElmntLst =fstElmnt.getElementsByTagName("firstname");
In the above code, I dont want to Hardcode the String firstname and wanted to send from the list of one of the child node. I don't see any method called getName().

Thank you
coolguy

Edited by: coolguy on Feb 18, 2008 6:01 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2008
Added on Feb 18 2008
4 comments
299 views