• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Parsing an xml file from an uri

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi lavanya,
sorry for my late reply.
it worked fine, thank you for the help.
regards andreas spiessl
 
reply
    Bookmark Topic Watch Topic
  • New Topic