xml初识-js

-------------------------------------------xml------------------------------------

<border>
<da>11111111111111</da>
<sb>222222222</sb>
<main info='你能获取我吗'>getData,6666666</main>
<foot>9999999999999</foot>
</border>

-------------------------------------------js-----------------------------

var xhr = new XMLHttpRequest();
xhr.open('GET','http://127.0.0.1:8848/xml/new.xml')
xhr.send();
xhr.onreadystatechange = function(e){
if(xhr.status == 200 && xhr.readyState==4){
  console.log(xhr)
  //var res = xhr.response;
  var str = xhr.responseText;
  var domParse = new DOMParser()
  var xmlDom = domParse.parseFromString(str,'text/xml')
  //拿到main标签以及中间的内容
  var contentDom = xmlDom.querySelector('main')
  console.log(contentDom,'contentDom');
  // 获取main标签里面的内容
  var innerData = contentDom.innerHTML;
  // 获取属性
  var info = contentDom.getAttribute('info');
  console.log(info,99)

上一篇:Ajax学习笔记


下一篇:V3 - Language Learning Teacher: Sean