need help for parsing one XML String

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

  1. [XaToA]

    [XaToA] Guest

    Hello.
    from one select to one database i extract one string in XML format.
    for example this:

    String cadenaXML="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+
    "<registros>\n
    <registro>\n<id>2</id>\n<nombremaquina>nombre1</nombremaquina>\n"+
    "<idcurso>56</idcurso>\n<nombrecursocastellano>curso cast
    1</nombrecursocastellano>\n"+
    "<nombrecursoingles>curso ing 1</nombrecursoingles>\n</registro>\n"+
    "<registro>\n<id>22</id>\n<nombremaquina>nombre2</nombremaquina>\n<idcurso>2
    23</idcurso>\n"+
    "<nombrecursocastellano>curso cast
    2</nombrecursocastellano>\n<nombrecursoingles>curso ing
    2</nombrecursoingles>\n"+
    </registro>\n</registros>";

    i want to parse this with jdom (or xerces) and to conver to this:

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

    Can you help me please?
    i am working in this problem during 3 days and i cannot solve it.
    I dont work with jdom and i am readin the doc but i dont get to solve this
    problem.

    Please can you help me?
    thanks
     
    [XaToA], Jul 26, 2003
    #1
    1. Advertising

  2. "[XaToA]" <>, Sat, 26 Jul 2003 15:35:43
    +0200:

    > Hello.
    > from one select to one database i extract one string in XML format.
    > for example this:
    >
    > String cadenaXML="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+
    > "<registros>\n
    > <registro>\n<id>2</id>\n<nombremaquina>nombre1</nombremaquina>\n"+
    > "<idcurso>56</idcurso>\n<nombrecursocastellano>curso cast
    > 1</nombrecursocastellano>\n"+
    > "<nombrecursoingles>curso ing 1</nombrecursoingles>\n</registro>\n"+
    > "<registro>\n<id>22</id>\n<nombremaquina>nombre2</nombremaquina>\n<idcurso>2
    > 23</idcurso>\n"+
    > "<nombrecursocastellano>curso cast
    > 2</nombrecursocastellano>\n<nombrecursoingles>curso ing
    > 2</nombrecursoingles>\n"+
    > </registro>\n</registros>";
    >
    > i want to parse this with jdom (or xerces) and to conver to this:
    >
    > 2 nombre1 56 curso cast 1 curso ing 1
    > 22 nombre2 22 curso cast 2 curso ing 2
    >
    > Can you help me please?
    > i am working in this problem during 3 days and i cannot solve it.
    > I dont work with jdom and i am readin the doc but i dont get to solve this
    > problem.


    Read the part about XSL transformations:

    http://java.sun.com/webservices/tutorial.html

    Use a stylesheet like this (it's not sufficient to get it totally like you
    want it to, but it should get things started; i really hate xsl syntax.)
    Be sure to set the parameters of the transformation to the correct
    encoding..

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
    <xsl:eek:utput encoding="UTF-8" method="html" omit-xml-declaration="yes"/>
    <xsl:template match="registros"><xsl:apply-templates select="registro"></xsl:apply-templates></xsl:template>
    <xsl:template match="registro"><xsl:apply-templates select="id|nombremaquina|idcurso|nombrecursocastellano|nombrecursoingles"></xsl:apply-templates><xsl:text>
    </xsl:text></xsl:template>
    <xsl:template match="id|nombremaquina|idcurso|nombrecursocastellano|nombrecursoingles"><xsl:text> </xsl:text><xsl:value-of select="text()"/><xsl:text> </xsl:text></xsl:template>
    </xsl:stylesheet>

    greets
    Bhun.
     
    dhek bhun kho, Jul 27, 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. [XaToA]
    Replies:
    0
    Views:
    6,957
    [XaToA]
    Mar 3, 2004
  2. loveNUNO
    Replies:
    2
    Views:
    925
    loveNUNO
    Nov 20, 2003
  3. Tony Prichard
    Replies:
    0
    Views:
    738
    Tony Prichard
    Dec 12, 2003
  4. Kee Nethery
    Replies:
    12
    Views:
    2,094
    Stefan Behnel
    Jun 27, 2009
  5. Erik Wasser
    Replies:
    5
    Views:
    464
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page