XML DOM prefix 屬性

定義和用法
prefix 屬性設置或返回屬性的命名空間首碼。
語法
attrObject.prefix
實例
下麵的代碼片段使用 loadXMLDoc() 把 "books_ns.xml" 載入 xmlDoc 中,並返回 "lang" 屬性的命名空間首碼:
實例
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write("Prefix: " + x.item(i).attributes[0].prefix);
document.write("<br>");
document.write("Local name: " + x.item(i).attributes[0].localName);
document.write("<br>");
document.write("Namespace URI: " + x.item(i).attributes[0].namespaceURI);
document.write("<br>");
document.write("Base URI: " + x.item(i).attributes[0].baseURI);
document.write("<br>");
document.write("<br>");
}
上面的代碼將輸出:
c
x
x
