parse one xml file, or String

Discussion in 'Java' started by [XaToA], Jul 25, 2003.

  1. [XaToA]

    [XaToA] Guest

    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>
     
    [XaToA], Jul 25, 2003
    #1
    1. Advertising

  2. [XaToA]

    Chris Smith Guest

    [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
     
    Chris Smith, Jul 26, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loveNUNO
    Replies:
    2
    Views:
    955
    loveNUNO
    Nov 20, 2003
  2. sachin
    Replies:
    1
    Views:
    364
    Tjerk Wolterink
    Dec 1, 2005
  3. jkflens
    Replies:
    2
    Views:
    1,535
    jkflens
    May 30, 2006
  4. Replies:
    19
    Views:
    1,169
    Daniel Vallstrom
    Mar 15, 2005
  5. Asif Iqbal
    Replies:
    0
    Views:
    166
    Asif Iqbal
    Aug 6, 2009
Loading...

Share This Page