construct2读取xml

前端之家收集整理的这篇文章主要介绍了construct2读取xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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、完成程序,运行结果


运行结果如下


原文链接:https://www.f2er.com/xml/294252.html

猜你在找的XML相关文章