XML DOM baseURI 属性

  • 定义和使用

    baseURI 属性返回节点的绝对基本URI。
  • 浏览器支持

    Internet Explorer Chrome FireFox Safari Opera
    不支持 4.0(包含)以上支持 2.0(包含)以上支持 3.0(包含)以上支持 9.0(包含)以上支持
  • 语法

    nodeObject.baseURI
    
  • 返回值

    返回值: 表示节点的绝对基本URI的字符串
    DOM 版本 核心级别3节点对象
  • 示例

    以下代码片段将 "books_ns.xml" 加载到xmlDoc中,并返回<title>元素的基本URI:
    <!DOCTYPE html>
    <html>
      <body>
      
      <p id="demo"></p>
      
      <script>
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
          if (xhttp.readyState == 4 && xhttp.status == 200) {
              myFunction(xhttp);
          }
      };
      xhttp.open("GET", "books_ns.xml", true);
      xhttp.send();
      
      function myFunction(xml) {
          var x, i, xmlDoc, txt;
          xmlDoc = xml.responseXML;
          txt = "";
          x = xmlDoc.getElementsByTagName("title");
          for (i = 0; i < x.length; i++) { 
              txt += "<p>Prefix: " + x.item(i).prefix +
              "<br>Local name: " + x.item(i).localName +
              "<br>Namespace URI: " + x.item(i).namespaceURI +
              "<br>Base URI: " + x.item(i).baseURI + "</p>";
          }
          document.getElementById("demo").innerHTML = txt; 
      }
      </script>
      
      </body>
    </html>
    
    尝试一下