JavaScript命名空间

来源:互联网 发布:外文电子图书数据库有 编辑:程序博客网 时间:2024/04/25 07:46

注:js加载xml文档是形成document对象。

1. 创建指定命名空间的元素

    newel = xmlDoc.createElementNS("p","edition") ;   //xmlDoc是xml文档被加载成功后形成的document对象。

    p:命名空间,edition是节点名称。

    创建后,元素的outerHTML是 <edition xmlns="p"></edition>

    localName : 不带前缀的节点名称,nodeName:是带前缀的节点名称。

2. 获取指定命名空间的元素

    var z=xmlDoc.getElementsByTagNameNS("p","edition");  // 获取命名空间为p,且节点名为edition的元素


关于节点的一些常用属性和方法:

newtext=xmlDoc.createTextNode("First");

newel.appendChild(newtext);

childNodes[0];

nodeValue;

namespaceURI;


0 0