XML格式數據解析


1.XML格式概念:可擴展標記語言 

2.XML格式數據

<?xml version="1.0" encoding="utf-8" ?>
<users>
  <user>
    <name>劉備</name>
    <sex>男</sex>
    <age>160</age>
    <desc>桃園三結義</desc>
  </user>
  <user>
    <name>隔壁小王</name>
    <sex>猛男</sex>
    <age>18</age>
    <desc>年輕氣力盛</desc>
  </user>
</users>

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
} } } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM