construct2读取xml
原创
©著作权归作者所有:来自51CTO博客作者生活在他方的原创作品,请联系作者获取转载授权,否则将追究法律责任
construct2官网上的说明,配的图实在太小,非常鄙视之。
construct2可以从网络或者本地读取xml数据,这里以本地文件为例
1、需要添加xml和ajax组件


2、新建xml文件
<?xml version="1.0" encoding="utf-8"?>
<bookstore>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
</bookstore>
3、导入xml文件
在“Files”点击鼠标右键导入

结果如下

4、获取文件
可以用“Request project file”获取

其中,“Tag”是个名称,可以随便取

也可以用“Request URL”来获取

其中,“URL”如果是本地的话,直接填写文件名。虽然在编辑器中可以建目录,但是发布以后都是在根目录下。

5、将ajax内容获取为xml
在这个时候,才能用xml组件的Load功能。

获取“AJAX.LastData”

6、用xpath语法获取内容
xpath教程参见:http://www.w3school.com.cn/xpath/index.asp

7、完成程序,运行结果

运行结果如下
