2012-06-30 3 views
-1

표준 RSS 피드를 구문 분석하여 테이블에 표시하는 iphone 앱이 있습니다. 그러나 클라이언트의 피드가 제공되었지만 응용 프로그램의 파서는 노드를 픽업 할 수 없으며 표준 RSS 피드가 아니므로 데이터를 구문 분석 할 수 없습니다.XSLT 또는 PHP 스크립트를 사용하여 XML 파일 재구성

<rss version="0.92"> 
     <channel> 
     <title>Feed</title> 
     <link>http://google.com</link> 
     <description> 
     Description here 
     </description> 
     <lastBuildDate>30 June +0100</lastBuildDate> 
     <language>en</language> 
      <event> 
       <eventID>123</eventID> 
       <name>Name here</name> 
       <date>2012-06-29</date> 
       <time>21:00</time> 
       <category>Arts</category> 
       <info> 
       Info here 
       </info> 
      </event> 
      <event> 
       <eventID>223</eventID> 
       <name>Name here</name> 
       <date>2012-06-30</date> 
       <time>22:00</time> 
       <category>Dance</category> 
       <info> 
       Info here 
       </info> 
      </event> 
    </channel> 
</rss> 

XSLT 또는 PHP 스크립트를 사용하여 표준의 RSS 피드 레이아웃이 XML 파일을 재구성 할 수있는 방법이 있나요 :

그들이 나에게 준 레이아웃은 다음과 같다? 인 다음 표준의 RSS 피드 레이아웃 :

<rss> 
    <channel> 
    <item> 
     <title> 
      <![CDATA[ Title here ]]> 
     </title> 
     <link> 
      http://www.theatre.com/ 
     </link> 
     <guid> 
     http://www.theatre.com 
     </guid> 
     <description> 
     <p> Description </p> 

     </description> 
     <dc:subject> 
     <![CDATA[ ]]> 
     </dc:subject> 
     <dc:date>2013-02-01T18:00:04+00:00</dc:date> 
     </item> 
    </channel> 
</rss> 
+1

하지도 않습니다 RSS의 유효성을 확인하십시오 : http://validator.w3.org/appc/#validate_by_input – Gordon

+1

출력 guid 요소의 컨텐츠는 어디에서 유래 되었습니까? 입력의 이벤트가 출력과 어떤 관련이 있습니까? cd : date의 컨텐츠는 어디에서 유래 되었습니까? –

+1

dc 출력에 대한 URL 바운딩이란 무엇입니까? –

답변

0

당신이 원하는 것을 분명하지 않다, 그래서이 스타일 시트는 당신이해야 할 수도 있습니다 무엇 단지 나타낸다. *이 문서를 생성합니다 귀하의 공급 샘플 입력에 적용

이 XSLT 1.0 스타일 시트 ....

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

    <xsl:template match="/"> 
<rss> 
    <channel> 
    <xsl:apply-templates select="rss/channel/event" /> 
    </channel> 
</rss> 
</xsl:template> 

<xsl:template match="event" > 
<item> 
    <title><xsl:value-of select="../title" /></title> 
    <link><xsl:value-of select="../link" /></link> 
    <guid>http://www.theatre.com</guid> 
    <description><xsl:value-of select="../description" /></description> 
    <subject><xsl:value-of select="category" /></subject> 
    <date><xsl:value-of select="date" />T<xsl:value-of select="time" />+00:00</date> 
</item> 
</xsl:template>  

</xsl:stylesheet> 
...

<?xml version="1.0" encoding="utf-8"?> 
<rss> 
    <channel> 
    <item> 
     <title>Feed</title> 
     <link>http://google.com</link> 
     <guid>http://www.theatre.com</guid> 
     <description> 
     Description here 
     </description> 
     <subject>Arts</subject> 
     <date>2012-06-29T21:00+00:00</date> 
    </item> 
    <item> 
     <title>Feed</title> 
     <link>http://google.com</link> 
     <guid>http://www.theatre.com</guid> 
     <description> 
     Description here 
     </description> 
     <subject>Dance</subject> 
     <date>2012-06-30T22:00+00:00</date> 
    </item> 
    </channel> 
</rss>  
관련 문제