How to extract each record from an XML doc containing multiple records

I want a sample code to get each record from a large xml document for parsing the data in it

Example for the XML doc is given below

<document>address

<record>0

<data>"11.97.23.174/32"

<record>address <data>

<record>address <data>

<record>subnet <data>

<record>ip <data>"10.97.23.174"</data></record>

</data></record>

</data></record>

</data></record>

</data></record>

<record>1

<data>FGT-MGT-PSS1

<record>address <data>

<record>address <data>

<record>subnet <data>

<record>ip <data>"10.97.23.180"</data></record>

and so on..........

For parsing I want the first record only. Means this much

<record>0

<data>"11.97.23.174/32"

<record>address <data>

<record>address <data>

<record>subnet <data>

<record>ip <data>"10.97.23.174"</data></record>

</data></record>

</data></record>

</data></record>

</data></record>

How to extract the records one by one?

[1219 byte] By [Renjana] at [2007-11-27 11:48:51]
# 1

did you want

<record>0

<data>"11.97.23.174/32"

<record>address <data>

<record>address <data>

<record>subnet <data>

<record>ip <data>"10.97.23.174"</data></record>

</data></record>

</data></record>

</data></record>

</data></record>

or

<record>0

<data>"11.97.23.174/32"

<record>address <data>

<record>address <data>

<record>subnet <data>

<record>ip <data>"10.97.23.174"</data></record>

mark07a at 2007-7-29 18:21:43 > top of Java-index,Java Essentials,Java Programming...
# 2

I want the full record.......means

<record>0

<data>"11.97.23.174/32"

<record>address <data>

<record>address <data>

<record>subnet <data>

<record>ip <data>"10.97.23.174"</data></record>

</data></record>

</data></record>

</data></record>

</data></record>

Renjana at 2007-7-29 18:21:43 > top of Java-index,Java Essentials,Java Programming...
# 3

you could possible write something using substring to find the instance of <record> and </record> and parse it that way but that's unreliable for websites that change and might be hard i would suggest an XML parser maybe one of these

http://www.destructor.de/xmlparser/index.htm

http://search.cpan.org/~msergeant/XML-Parser/Parser.pm

mark07a at 2007-7-29 18:21:43 > top of Java-index,Java Essentials,Java Programming...
# 4

Use dom4j : you can find an example at

http://www.dom4j.org/guide.html

use the FAST LOOPING example instead of for statement, if you use an if statement you will just get the first record, this is fast and easy, then print each element to a file or output.

java_queena at 2007-7-29 18:21:43 > top of Java-index,Java Essentials,Java Programming...