2013-10-04 53 views
0

我對FTL相當陌生,並且遇到問題。我必須從FTL代碼中讀取XML,然後遍歷它才能顯示數據。問題是FTL上的互聯網沒有太多的文檔,我無法總結如何實現這一目標。以下是我寫的示例代碼,請讓我知道我做錯了什麼。如何從FTL讀取XML節點並遍歷它們

XML文件

<response status="success"> 
<threads> 
<thread type="thread" href="/threads/id/4999"> 
<id type="int">4999</id> 
<subject type="string"> 
Testing of the XML and FTL 1 
</subject> 
<message_rating type="float">0.0</message_rating> 
<thread type="thread" href="/threads/id/4999"/> 
<last_edit_time type="date_time">2013-10-01T14:08:04+00:00</last_edit_time> 
<last_edit_author type="user" href="https://stackoverflow.com/users/id/149"> 
</last_edit_author> 
<labels/> 
<board type="board" href="/boards/id/10031"/> 
<views> 
<count type="int">1</count> 
</views> 
</linear> 
<read> 
<count type="int">1</count> 
</read> 
<count type="int">1</count> 

</thread> 
<thread type="thread" href="/threads/id/4999"> 
<id type="int">4998</id> 
<subject type="string"> 
Testing of the XML and FTL 2 
</subject> 
<message_rating type="float">1.0</message_rating> 
<thread type="thread" href="/threads/id/4999"/> 
<last_edit_time type="date_time">2013-10-02T14:08:04+00:00</last_edit_time> 
<last_edit_author type="user" href="https://stackoverflow.com/users/id/149"> 
</last_edit_author> 
<labels/> 
<board type="board" href="/boards/id/10031"/> 
<views> 
<count type="int">2</count> 
</views> 
</linear> 
<read> 
<count type="int">1</count> 
</read> 
<count type="int">1</count> 

</thread> 
. 
. 
. 
. 
. 
. 
. 
. 
. 
</threads> 
</response> 

我想提出一個REST調用返回上面的XML,而我寫的FTL的代碼如下。

有了FTL響應,我需要獲取主題,視圖計數和論壇URL。

<#assign active_board = restadmin("/boards/id/10031/threads")> 

<!-- I AM NOT SURE HOW TO ITERATE THORUGH THE XML AND GET THE LIST OF ABOVE MENTIONED THINGS I NEED AND DISPLAY IT ON FRONT END --> 

<#assign message_list = restadmin("/threads/id/4999").thread.messages> <!--THIS IS ANOTHER REST CALL--> 
     <#assign count = message_list.topic.kudos.count?number> 
     <#list message_list.linear.message as m> 
      <# count = count+m.kudos.count> 
     </#list> 
+0

我不確定你卡在哪裏。例如,你有紅色的http://freemarker.org/docs/xgui.html嗎? 「restadmin」是已經存在的東西,或者你試圖實現的東西? – ddekany

回答

0

我已經能夠從FTL代碼讀取XML。這http://freemarker.org/docs/xgui_expose_dom.html幫了很多。我現在可以根據需要從XML讀取所有必要的細節。

問題是我沒有提供父節點來開始。以下查詢工作。

<#assign threads = restadmin("/boards/id/${coreNode.id}/threads?restapi.response_style=view&page_size=10&page=15").threads/> 

我不知道這會有多大幫助,但我發佈這個答案僅僅是因爲FTL文檔太少。