2011-07-05 3 views
4

나는 거대한 XML 파일을 가지고 있으며 그것을 읽을 수있는 형식으로 변환하고 싶다.XML을 읽을 수있는 것으로 변환하는 방법은 무엇입니까?

이 내 xml 파일과 같은 모습입니다 :

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

그래서 나는이 같은 5000 개 이상의 항목이와 나는 온라인으로 넣어 그래서 난 쉽게 읽을 수 있습니다합니다. 어떻게 변환 할 수 있습니까?

지구

지구는 우리가 살고있는 장소 :

내가 갖고 싶어 출력입니다. (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

이렇게 XML 스타일 시트라고하는 XSLT를 사용할 수 있습니다.

그들에 대한

읽고 여기 투어 걸릴 : 당신은 간단한 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> 
관련 문제