[英]How do I read XML nodes from FTL and iterate through them
我对FTL相当陌生,并且一直遇到问题。 我必须从FTL代码中读取XML,然后对其进行遍历以显示数据。 问题是Internet上没有太多有关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>
我已经能够从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的可用文档太少。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.