need help for parsing one XML String

X

[XaToA]

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
 
D

dhek bhun kho

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.
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top