Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > parse one xml file, or String

Reply
Thread Tools

parse one xml file, or String

 
 
[XaToA]
Guest
Posts: n/a
 
      07-25-2003
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>


 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      07-25-2003
[XaToA] wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to read parse data from two file to generate one one file Asif Iqbal Ruby 0 08-06-2009 04:47 PM
ElementTree.XML(string XML) and ElementTree.fromstring(string XML)not working Kee Nethery Python 12 06-27-2009 06:06 AM
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Using One XSLT and multiple XML Problem (One is XML and another one is XBRL) loveNUNO XML 2 11-20-2003 06:47 AM



Advertisments