如何从FTL读取XML节点并迭代它们

时间:2013-10-04 04:17:41

标签: freemarker

我对FTL很新,并且遇到了问题。我必须从FTL代码中读取XML,然后遍历它以显示数据。问题是没有太多关于FTL的互联网文档,我无法总结如何实现这一点。下面是我写的示例代码,请让我知道我做错了什么。

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="/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="/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>

1 个答案:

答案 0 :(得分: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的文档太少了。