2011-07-05 13 views
4

私は巨大なXMLファイルを持っていて、それを読みやすい形式に変換したいのです。だから私はこのような5000個の以上のエントリを持っていると私は簡単にそれらを読むことができるように、オンラインでそれらを置きたいXMLを読み込み可能なものに変換するには?

<entries> 
<entry title="earth" id="9424127" date="2006-04-19T08:22:16.140"> 
<![CDATA[earth is the place where we live.]]> 
</entry> 
</entries> 

これは私のxmlファイルがどのように見えるかです。どうすれば変換できますか?

これは私が持っていると思います出力されます:

地球

地球は私たちが住んでいる場所です。 (2006-04-19T08:22:16.140)

答えて

5

:あなたの特定のケースでhttp://www.w3schools.com/xsl/

は、むしろ簡単な解決策のようなものを見ることができます表。

たとえば、このスタイルシート:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output indent="yes"/> 
    <xsl:strip-space elements="*"/> 

    <xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="/entries"> 
    <html> 
     <body> 
     <table border="1"> 
      <xsl:apply-templates/> 
     </table> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="entry"> 
    <tr> 
     <td><xsl:value-of select="@title"/></td> 
     <td> 
     <xsl:apply-templates/> 
     </td> 
     <td>(<xsl:value-of select="@date"/>)</td> 
    </tr> 
    </xsl:template> 

</xsl:stylesheet> 

を作成します。

<html> 
    <body> 
    <table border="1"> 
     <tr> 
     <td>earth</td> 
     <td> earth is the place where we live. </td> 
     <td>(2006-04-19T08:22:16.140)</td> 
     </tr> 
    </table> 
    </body> 
</html> 
+0

すごいです!これは問題を解決します。どうもありがとう! – sensahin

+0

大歓迎です! –

+0

私はまた、日付を出力するのを忘れていることに気付きました。ちょうど私の答えを更新しました。 –

1

これにはXSLTといういわゆるXMLスタイルシートを使用することができます。

それらについて

読むと、ここでツアー取る:あなたは、単純なHTMLを作成するために、XSLTスタイルシートを使用することができ

<?xml version="1.0"?> 

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
    <html> 
    <body> 
     <xsl:for-each select="entry"> 
      <br /> 
      <!-- Process CDATA somehow --> (<xsl:value-of select="@date"/>) 
     </xsl:for-each> 
    </body> 
    </html> 
</xsl:template> 

</xsl:stylesheet> 
関連する問題