XML DOM setAttributeNode() ਮਹੱਤਵਪੂਰਨ ਮੱਥਾ
ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ
setAttributeNode()
ਨਵਾਂ ਪ੍ਰਤੀਯੋਗੀ ਜੋੜਨ ਦਾ ਮਹੱਤਵਪੂਰਨ ਮੱਥਾ
ਜੇਕਰ ਅਣੁਕਤ ਵਿੱਚ ਮੌਜੂਦ ਹੈ ਤਾਂ ਉਸ ਨੂੰ ਨਵੇਂ ਪ੍ਰਤੀਯੋਗੀ ਨਾਲ ਬਦਲ ਦਿੰਦਾ ਹੈ。
ਜੇਕਰ ਨਵਾਂ ਪ੍ਰਤੀਯੋਗੀ ਮੌਜੂਦਾ ਪ੍ਰਤੀਯੋਗੀ ਨੂੰ ਬਦਲ ਦਿੰਦਾ ਹੈ ਤਾਂ ਉਸ ਪ੍ਰਤੀਯੋਗੀ ਨੂੰ ਵਾਪਸ ਦਿੰਦਾ ਹੈ ਨਾਲ ਹੀ null ਵਾਪਸ ਦਿੰਦਾ ਹੈ。
ਗਣਨਾ
elementNode.setAttributeNode(att_node)
ਪੈਰਾਮੀਟਰ | ਵਰਣਨ |
---|---|
att_node | ਲਾਜ਼ਮੀ ਹੈ। ਜੋ ਸੈਟ ਕੀਤੇ ਜਾਣ ਵਾਲੇ ਪ੍ਰਤੀਯੋਗੀ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰੋ |
ਇੱਕ ਉਦਾਹਰਣ
ਹੇਠ ਲਿਖੇ ਕੋਡ "books.xml" ਨੂੰ xmlDoc ਵਿੱਚ ਲੋਡ ਕਰੇਗਾ ਅਤੇ ਸਾਰੇ <book> ਅਣੁਕਤਾਂ ਨੂੰ "edition" ਅਣੁਕਤਾ ਜੋੜੇਗਾ:
ਵਾਰਤਾ ਹੈ xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { ਜੇਕਰ (this.readyState == 4 && this.status == 200) { ਮਿਊਚਨਲ ਫੰਕਸ਼ਨ(ਇਸ); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); ਕਿਉਂਕਿ ਮਿਊਚਨਲ ਫੰਕਸ਼ਨ ਮਿਊਚਨਲ ਫੰਕਸ਼ਨ(xml) { ਵਾਰਤਾ ਹਨ x, y, z, i, newatt, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName('book'); for (i = 0; i < x.length; i++) { newatt = xmlDoc.createAttribute("edition"); newatt.value = "first"; x[i].setAttributeNode(newatt); } ਬਾਹਰੀ ਹੁੰਦਾ ਹੈ ਕਿ ਸਾਰੇ 'ਸੰਸਕਰਣ' ਪ੍ਰਤੀਯੋਗੀ ਮੁੱਲਾਂ ਬਾਹਰ ਕਰੋ for (i = 0; i < x.length; i++) { txt += "Edition: " + x[i].getAttribute("edition") + "<br>"; } document.getElementById("demo").innerHTML = txt; }