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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Get Attribute of a NodeList?

843834Aug 3 2006 — edited Aug 3 2006
Can anyone help me get the 'user_agent' attribute of the TagName 'device' in the following code. I'm sure it's not that hard but I can get it.

Many thanks in advance.


// Create DOM XML document factory
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File("wurfl.xml"));

// normalize text representation
doc.getDocumentElement().normalize();
System.out.println("Root element of the doc is " +
doc.getDocumentElement().getNodeName());

NodeList listOfDevices = doc.getElementsByTagName("device");
int totalDevices = listOfDevices.getLength();
System.out.println("Total no of devices: " + totalDevices);

for(int s=0; s<listOfDevices.getLength() ; s++){

// need to get the attribute called user_agent from the 'device' tag here

}

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 31 2006
Added on Aug 3 2006
1 comment
96 views