File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
Consider Paul's rocket mass heater.
subject: Parsing an xml file from an uri
Similar Threads
DOM Parser - How To Get the Attribute Value
Filtering XML using DOM
i need to create a xml file from Jtree
How do I retrieve ancestor-or-self nodelist in a JSP page using the JSP XML taglibs?
Hibernate mapping and versioning issues