File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes iterate through string get elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "iterate through string get elements" Watch "iterate through string get elements" New topic

iterate through string get elements

dale con
Ranch Hand

Joined: Apr 15, 2005
Posts: 93
hi all can someone please tell me how i convert a string to xml, so that i can iterate through it and grab the elements and their values

e.g. if my string is this
String xml = "<person><firstname>first</firstname><lastname>first</lastname></person>";

i want to iterate through to get the firstname and lastname elements and then get their vlaues

thanks for any help
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
You can use XML parsers.

Look at the javax.xml.parsers package.

Regards,<br />Seb<br /> <br />SCJP 1.4
Naveen Vooka

Joined: Oct 13, 2004
Posts: 25
Have a look at various XML parsers available

Naveen Vooka
DevSquare - Online Application Development
It is sorta covered in the JavaRanch Style Guide.
subject: iterate through string get elements
It's not a secret anymore!