-2

Here is the XML I want to parse:

"<Result>"
+ "<columnName><![CDATA[Role_Id]]></columnName>"
+ "<Row><col><![CDATA[0]]></col><col><![CDATA[zero]]></col></Row>"
+ "<Row><col><![CDATA[1]]></col><col><![CDATA[one]]></col></Row>"
+ "<Row><col><![CDATA[2]]></col><col><![CDATA[two]]></col></Row>" + "</Result>";

and I would like the following output:

0,zero
1,one
2,two

but when I'm trying to parse it, I get

0 1 2
4

4 回答 4

3

You could try to use JAX-B, it should do the trick pretty easily.

An "hello world" example for JAX-B: http://www.mkyong.com/java/jaxb-hello-world-example/

于 2012-11-06T10:31:50.903 回答
0

使用 DOM、JDOM、SAX 等库。Internet 上有很多可用的教程。

于 2012-11-06T09:50:55.613 回答
0

想到 XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" />
    <xsl:template match="/Result">
        <xsl:apply-templates select="Row"/>
    </xsl:template>

    <xsl:template match="Row">
        <xsl:value-of select="col[1]"/>,<xsl:value-of select="col[2]" />
        <xsl:text>&#10;</xsl:text>
    </xsl:template>
</xsl:stylesheet>
于 2012-11-06T10:30:13.273 回答
-1

Another alternative to XSLT would be SLAX. Syntax is much better on the eyes, and more fun to write:

libslax

于 2012-11-06T17:57:47.807 回答