XML格式数据解析

1.XML格式概念:可扩展标记语言 

2.XML格式数据

"1.0" encoding="utf-8" ?>

  
    刘备
    
    160
    桃园三结义
  
  
    隔壁小王
    猛男
    18
    年轻气力盛
  

3.在php文件中读取xml格式的文件  

php
header('content-type:text/xml;charset=utf-8');       //content-type:text/xml;
$res = file_get_contents("01-data.xml"); echo $res; 

?>

4.发送ajax请求,获取xml数据  xml格式数据需要使用.responseXML来进行接收,得到一个dom对象

var bt = document.getElementById('bt')
        bt.onclick = function () {
            var xhr =new XMLHttpRequest()
            xhr.open("get", "aa.php")
            xhr.send()
    xhr.onreadystatechange=function(){
        if(xhr.readyState===4){
            if(xhr.status===200){
                console.log(xhr.responseXML)      //xhr.responseXML
} } } }

 

你可能感兴趣的:(XML格式数据解析)