XML DOM

作者: 假装会编程 | 来源:发表于2016-10-30 12:54 被阅读0次
    • 跨域访问禁止 -> JS同源策略
      出于对安全性的考虑,现代浏览器禁止跨域访问,意即网页及其所加载的XML文件必须处于同一服务器中
    DOM
    • 用于XML的标准对象模型;用于XML的标准编程接口;独立于平台和语言;W3C标准;
    • DOM处理常见的一种错误是认为元素节点包含文本,e.g.:<year>2005</year>;该例中是元素year拥有一个值为2005的文本节点,2005不是元素year的值
    • 编程接口
    • 属性: nodeName、nodeValue、parentNode、childNodes、attributes、firstChild、nextSibling
    • 方法: getElementByTagName、appendChild、removeChild、attributes.getNamedItem('name')
    • xhr.documentElement为XML树结构的根元素
    • nodeType: 1 Element, 2 Attribute, 3 Text, 8 Comment, 9 Document...
    • nodeName: Element.nodeName = tagName; Attribute.nodeName = attribute; Text.nodeName = #text; Document.nodeName = #document;(注意document与xhr.documentElement是不同的东西)
    • nodeValue: Element.nodeValue = undefined; Text.nodeValue = text; Attribute.nodeValue = attribute;
    • 浏览器差异
    • 解析器的加载不同
    • 空白处理不同,Firefox以及其他一些浏览器,会把空的空白或换行作为文本节点来处理,而IE会忽略空白和换行。
      (详见http://www.w3school.com.cn/example/xdom/books.xml,使用不同浏览器尝试加载该XML并获取遍历根节点的childNodes,结果不同);

    相关文章

      网友评论

        本文标题:XML DOM

        本文链接:https://www.haomeiwen.com/subject/wxquuttx.html