This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Parsing an xml file from an uri Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing an xml file from an uri" Watch "Parsing an xml file from an uri" New topic

Parsing an xml file from an uri


Joined: Jan 09, 2002
Posts: 26
hello all,
i am learning xml and now i want to access a xml file like this and want to access the values.

my question now is:
how can i access the value from the user - userrole like:

can somebody help me please.
andreas spiessl
lavanya subramanian
Ranch Hand

Joined: Nov 03, 2000
Posts: 52
Hio andreas,
Welcome to XML.

first the xml code is not well-formed,There are many occurances of '<' and '>' at unwanted places,so correct that.

i'm sending u the code for ur problem

DOMParser parser = new DOMParser();
parser.parse("your file goes here");
Document doc = parser.getDocument();
NodeList nl1 = doc.getElementsByTagName("userrole");
Node n = null;
for(int i=0;i<nl1.getLength();i++)
n = nl1.item(i);
if(n.getNodeType() == Node.ELEMENT_NODE)
NodeList nl2 = n.getChildNodes();
String temp[] = new String(nl2.getLength());
for(int k=0;k<nl2.getLength();k++)
catch(Exception e)
This would help.

Joined: Jan 09, 2002
Posts: 26
hi lavanya,
sorry for my late reply.
it worked fine, thank you for the help.
regards andreas spiessl
It is sorta covered in the JavaRanch Style Guide.
subject: Parsing an xml file from an uri
jQuery in Action, 3rd edition