Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > need help for parsing one XML String

Reply
Thread Tools

need help for parsing one XML String

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


 
Reply With Quote
 
 
 
 
dhek bhun kho
Guest
Posts: n/a
 
      07-27-2003
"[XaToA]" <granbilbao_NOSPAM_@latinmail.com>, 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" xmlnssl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xslutput 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|nombrecursocastel lano|nombrecursoingles"></xsl:apply-templates><xsl:text> </xsl:text></xsl:template>
<xsl:template match="id|nombremaquina|idcurso|nombrecursocastell ano|nombrecursoingles"><xsl:text> </xsl:text><xsl:value-of select="text()"/><xsl:text> </xsl:text></xsl:template>
</xsl:stylesheet>

greets
Bhun.
 
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
ElementTree.XML(string XML) and ElementTree.fromstring(string XML)not working Kee Nethery Python 12 06-27-2009 06:06 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM
parsing one xml String with JDOM [XaToA] Java 0 03-03-2004 08:17 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
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57