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>
我不确定你卡在哪里。例如,你有红色的http://freemarker.org/docs/xgui.html吗? “restadmin”是已经存在的东西,或者你试图实现的东西? – ddekany