xml 文件处理

//html中ajax注册事件响应报文要改成
// 注册事件
ajax.onreadystatechange = function () {
if (ajax.readyState==4 && ajax.status==200) {
// 知道返回的是 xml
console.log(ajax.responseXML);

// 获取xml中的document对象哦
var persons = ajax.responseXML.querySelectorAll('person');
console.log(persons);
  }
}

//php中引用xml文件
<?php 
// 设置 返回的为 xml
header('content-type:text/xml; charset= utf-8');
// 读取xml文件 并返回
echo file_get_contents('info/star.xml');
?>


//xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<star>
<yiname>汪星人</yiname>
<name>汪峰</name>
<wife>章子怡</wife>
<song>北京,北京</song>
<kuzi>皮裤</kuzi>
</star>

猜你喜欢

转载自www.cnblogs.com/vzaiBoke/p/9072254.html
今日推荐