XML DOM setAttributeNode() ����

�������÷�

setAttributeNode() ���������µ����Խڵ㡣

����Ԫ�����Ѿ�����ָ�����Ƶ����ԣ���ô�����Խ����������������������������������е����ԣ��򷵻ر����������ԣ����򷵻� NULL��

�﷨��

elementNode.setAttributeNode(att_node)
���� ����
att_node ���衣�涨Ҫ���õ����Խڵ㡣

˵��

�÷������� Element �ڵ������Լ��������µ� Attr �ڵ㡣������ǰ Element �Ѿ�����һ��ͬ�������ԣ��÷��������������滻�Ǹ����ԣ����ر��滻�� Attr �ڵ㡣�������������������ԣ��÷�����Ϊ Element ����һ�������ԡ�

ͨ������ setAttribute() �������� setAttributeNode() �򵥡�

ʵ��

�����е������У����ǽ�ʹ�� XML �ļ� books.xml���Լ� JavaScript ���� loadXMLDoc()��

�����Ĵ����� "books.xml" �е����� <book> Ԫ�������� "edition" ���ԣ�

xmlDoc=loadXMLDoc("books_ns.xml");

x=xmlDoc.getElementsByTagName("book")[0];
ns="http://www.w3school.com.cn/edition/";

x.setAttributeNS(ns,"edition","first");

document.write(x.getAttributeNS(ns,"edition"));

������

first