XML DOM length ਪ੍ਰਤੀਯੋਗਿਤਾ
ਵਿਆਖਿਆ ਅਤੇ ਵਰਤੋਂ
length
ਪ੍ਰਤੀਯੋਗਿਤਾ ਨੋਡ ਦੇ ਚਿੰਨ੍ਹ ਨੂੰ ਚਾਰਕਟਰਾਂ ਦੇ ਅਨੁਸਾਰ ਲੰਬਾਈ ਵਾਪਸ ਦੇਣ ਵਾਲੀ ਪ੍ਰਤੀਯੋਗਿਤਾ।
ਵਰਤੋਂ
commentNode.length
ਉਦਾਹਰਣ
ਹੇਠ ਦਾ ਕੋਡ "books_comment.xml" ਨੂੰ xmlDoc ਵਿੱਚ ਲੋਡ ਕਰੇਗਾ ਅਤੇ ਪਹਿਲੇ <title> ਇਲੈਕਟਰੌਨ ਵਿੱਚ ਟੈਕਸਟ ਨੋਡ ਅਤੇ ਲੰਬਾਈ ਪ੍ਰਾਪਤ ਕਰੇਗਾ:
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].length + "<br>"; } } document.getElementById("demo").innerHTML = txt; }
ਉੱਪਰੋਕਤ ਉਦਾਹਰਣ ਵਿੱਚ ਅਸੀਂ ਸਰਕਟ ਅਤੇ if ਟੈਸਟ ਸਟੇਟਮੈਂਟ ਵਰਤੇ ਹਨ, ਤਾਕਿ ਅਸੀਂ ਸਿਰਫ ਟਿੱਪਣੀ ਨੋਡ ਨੂੰ ਹੀ ਪ੍ਰਬੰਧ ਕਰੀਏ।ਟਿੱਪਣੀ ਨੋਡ ਦਾ ਨੋਡ ਟਾਈਪ 8 ਹੈ。