2012-03-28 5 views
0

xmlファイルをこの形式に解析/変換できるツールはありますか? 変換が必要なデータがたくさんあります。 Perl XML :: SimpleとData :: Dumperでこれを行うことができます。他のツールはありますか?XMLパーサー/コンバーター

から -

<create> 
    <New> 
     <Name>John</Name> 
    </New> 
</create> 

へ -

古き良き XSLTについて
body = { 
    "create" => { 
     "New" => { "Name" => "John" } 
    } 
    } 

答えて

2

どのように変換するXSLの使用についてのような何か: - あなたに

Perl XML::XSLT Module

3

どのように?

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:output method="text"/> 
    <xsl:strip-space elements="*"/> 

    <xsl:template match="/"> 
    <xsl:text>body = {</xsl:text> 
    <xsl:apply-templates/> 
    <xsl:text>}&#0010;</xsl:text> 
    </xsl:template> 

    <xsl:template match="*"> 
    <xsl:text>&#0010; "</xsl:text> 
    <xsl:value-of select="name(.)"/> 
    <xsl:text>" => {</xsl:text> 
    <xsl:apply-templates/> 
    <xsl:text> }&#0010;</xsl:text> 
    </xsl:template> 

    <xsl:template match="*[text()]"> 
    <xsl:text> "</xsl:text> 
    <xsl:value-of select="name(.)"/> 
    <xsl:text>" => "</xsl:text> 
    <xsl:value-of select="text()"/> 
    <xsl:text>"</xsl:text> 
    </xsl:template> 

</xsl:stylesheet> 
+0

+1をあなたが私の前にそれに答えて! –