Pages

WELCOME TO MY BLOG

Sabtu, 22 Januari 2011

Daily Game Jan 22 - Ancient Powers NX8

Embark on a quest to raise your beloved back from the dead.

Ancient Powers NX8 is powered by dailygame.org

Jumat, 21 Januari 2011

Daily Game Jan 21 - Massive war 2

Pick one of the three factions and go on your quest to conquer the planet.

Massive war 2 is powered by dailygame.org

Kamis, 20 Januari 2011

Daily Game Jan 20 - Dungeon Developer

Play as the dungeon. Develop yourself in such a way that the band of adventurers will get to the 15th floor and slay the dragon.

Dungeon Developer is powered by dailygame.org

Senin, 17 Januari 2011

Mozilla Firefox vs Internet Explorer

Dua browser popular, yaitu Internet Explorer dan Mozilla, sama-sama mensuport W3C DOM. Diantara keduanya, ada perbedaan antara IE DOM dan Mozilla DOM. Perbedaan yang menjadi perhatian adalah bagaimana cara menangani white-space text node. IE, ketika menggunakan node.childNodes[ ], tidak langsung berisi node white-space. Di mozilla, node tersebut akan masuk ke array.

Potongan kode akan menampilkan alert jumlah child node yang dimiliki elemen root.

xmlDoc.load("books.xml");
var x=xmlDoc.documentElement.childNodes;
alert(x.length)
for (i=0;i<x.length;i++)
{
document.write(x[i].nodeType);
document.write("<br />");
}

Pada IE akan melewati text yang membuat node white-space yang dibuat di antara node (misalnya karakter pindah baris), sedangkan di Mozilla tidak demikian. Sedikit contoh script diatas jika anda buka dengan Mozilla maka akan menampilkan elert 9, sedangkan di IE adalah 4.

Untuk melakukan iterasi dari awal sampai akhir dan mengabaikan text node tersebut, cek tipe node-nya. Sebuah elemen node mempunyai tipe 1, sedangkan text node tipe 3 dan comment node mempunyai tipe 8. Untuk melewati text node(white-space), caranya hanya memproses tipe 3 (text node) dan tipe 8 (comment node).

xmlDoc.load("books.xml");
var x=xmlDoc.documentElement.childNodes;
for (var i=0;i<x.length;i++)
{
if ((x[i].nodeType!=3)&&(x[i].nodeType!=8))
{
//tidak memproses text node dan comment node dan document.write(x[i].nodeName);
document.write("<br />");
}
}

Cara terbaik untuk memproses elemen node adalah dengan iterasi dari awal sampai akhir dari child node dan hanya memproses yang bertipe 1:

xmlDoc.load("books.xml");

var x=xmlDoc.documentElement.childNodes;

for (var i=0;i<x.length;i++)
{
if (x[i].nodeType==1)
{
//Process jika elemen node
document.write(x[i].nodeName);
document.write("<br />");
}


Powered By Blogger