parse one xml file, or String

X

[XaToA]

Hello.
I have the bellow xml file (or String).
i want to parse the file for producing this:

2 nombre1 56 curso cast 1 curso ing 1
22 nombre2 22 curso cast 2 curso ing 2

can any body help me please? i don't know how can i use the xml parserws
(DOM, SAX).
Please help me
thanks


<?xml version="1.0" encoding="ISO-8859-1"?>
<registros>
<registro>
<id>2</id>
<nombremaquina>nombre1</nombremaquina>
<idcurso>56</idcurso>
<nombrecursocastellano>curso cast 1</nombrecursocastellano>
<nombrecursoingles>curso ing 1</nombrecursoingles>
</registro>
<registro>
<id>22</id>
<nombremaquina>nombre2</nombremaquina>
<idcurso>223</idcurso>
<nombrecursocastellano>curso cast 2</nombrecursocastellano>
<nombrecursoingles>curso ing 2</nombrecursoingles>
</registro>
</registros>
 
C

Chris Smith

Hello.
I have the bellow xml file (or String).
i want to parse the file for producing this:

2 nombre1 56 curso cast 1 curso ing 1
22 nombre2 22 curso cast 2 curso ing 2

can any body help me please? i don't know how can i use the xml parserws
(DOM, SAX).

There are a few ways to use XML parsers, but the most universal is JAXP.
Looks something like:

DocumentBuilder builder = DocumentBuilderFactory()
.newInstance().newDocumentBuilder();
Document doc = builder.parse(new File("test.xml"));

or:

SAXParser parser = SAXParserFactory
.newInstance().newSAXParser();
parser.parse(new File("test.xml"), new MyHandler());

If you choose to use SAX, see the API docs for DefaultHandler. If you
choose to use DOM, see the API docs for the org.w3c.dom package.

If the document is in a String, there are versions of the parse methods
in DocumentBuilder and SAXParser that use InputSource instead of a File.
An InputSource can be constructed from a Reader, which can be a
StringReader.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top