File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Parsing an xml file from an uri

snoofle
Greenhorn

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.
tia
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

try
{
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)
{
if(n.hasChildNodes())
{
NodeList nl2 = n.getChildNodes();
String temp[] = new String(nl2.getLength());
for(int k=0;k<nl2.getLength();k++)
{
temp[k]=nl2.item(k).getNodeValue());
}
}
}
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
This would help.
snoofle
Greenhorn

Joined: Jan 09, 2002
Posts: 26
hi lavanya,
sorry for my late reply.
it worked fine, thank you for the help.
regards andreas spiessl
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing an xml file from an uri