ਕੋਰਸ ਸਿਫਾਰਸ਼
XML DOM data ਗੁਣ
data
ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ
ਗਿਆਨ ਸਿਧਾਂਤ
commentNode.data
ਉਦਾਹਰਣ
ਹੇਠ ਦਾ ਕੋਡ "books_comment.xml" ਨੂੰ xmlDoc ਵਿੱਚ ਲੋਡ ਕਰੇਗਾ ਅਤੇ ਪਹਿਲੇ <book> ਈਲੈਮੈਂਟ ਵਿੱਚ ਟਿੱਪਣੀ ਟੈਕਸਟ ਨੂੰ ਪ੍ਰਿੰਟ ਕਰੇਗਾ:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books_comment.xml", true); xhttp.send(); function myFunction(xml) { var x, i, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book")[0].childNodes; for (i = 0; i < x.length; i++) { if (x[i].nodeType == 8) { txt += x[i].data + "<br>"; } } document.getElementById("demo").innerHTML = txt; }
ਉੱਪਰੋਕਤ ਉਦਾਹਰਣ ਵਿੱਚ, ਅਸੀਂ ਸਿਰਫ ਟਿੱਪਣੀ ਨੋਡ ਨੂੰ ਹੱਲ ਕਰਨ ਲਈ ਸਰਕਟ ਅਤੇ if ਟੈਸਟ ਸਟੇਂਸ ਵਰਤੇ ਹਨ।ਟਿੱਪਣੀ ਨੋਡ ਦਾ ਨੋਡ ਟਾਈਪ 8 ਹੈ。