XML DOM firstChild ຂໍ້ສະແດງ

ຄູ່ມື Document ໂອລິຍາ

ການອະທິບາຍ ແລະການນໍາໃຊ້

ຂໍ້ສະເພາະ ແລະການນໍາໃຊ້ firstChild ຂໍ້ສະແດງຂອງ XML DOM ສາມາດຫຼັກກະຕຸບານຂອງໂຕເລື່ອງຂອງໂຕເລື່ອງ.

ວິທິການ:

documentObject.firstChild 

ຄຳເຕືອນ ແລະ ຄວາມເຫັນ:

ຄວາມເຫັນ:Internet Explorer ຈະທຳລາຍຂອງຫົວໜ້າທີ່ສ້າງຂຶ້ນລະຫວ່າງຫົວໜ້າ (ເຊິ່ງເປັນຫົວໜ້າການຫົນຈະຫຼວງ), ແຕ່ Mozilla ຈະບໍ່ເຮັດແນວນັ້ນ. ເນື່ອງຈາກນັ້ນ, ໃນຄວາມຈິງ, ພວກເຮົາຈະໃຊ້ຫົວນວຍການທີ່ກວດຫົວໜ້າຜູ້ລົງມາທໍາອິດຂອງຫົວໜ້າ.

ປະກອບການຂອງຫົວໜ້າຂອງຂອງຕົວເລື່ອງສະແດງແມ່ນ 1, ແລະຖ້າຫົວໜ້າຜູ້ລົງມາບໍ່ແມ່ນຫົວໜ້າສະແດງ, ມັນຈະຍ້າຍໄປຫາຫົວໜ້າໃນຕໍ່ໄປ, ແລະສືບຕໍ່ກວດຫົວໜ້ານັ້ນວ່າມັນແມ່ນຫົວໜ້າສະແດງຫຼືບໍ່. ຂະບວນການນີ້ຈະສືບຕໍ່ຈົນກວ່າຫົວໜ້າສະແດງຜູ້ລົງມາທໍາອິດຖືກພົບ. ດ້ວຍວິທີນີ້, ພວກເຮົາສາມາດໄດ້ຮັບຜົນທີ່ຖືກຕ້ອງໃນ Internet Explorer ແລະ Mozilla.

Tip:For more information on the differences between XML DOM in IE and Mozilla browsers, please visit our DOM Browser Chapter.

Example

In all examples, we will use the XML file books.xml, and JavaScript function loadXMLDoc().

The following code snippet can display the node name and node type of the first child node of the document:

//Check if the first node is an element node
function get_firstchild(n)
{
var x=n.firstChild;
while (x.nodeType!=1)
{
x=x.nextSibling;
}
return x;
}
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
var x=get_firstchild(xmlDoc);
document.write("Nodename: " + x.nodeName);
document.write(" (nodetype: " + x.nodeType + ")");

Output:

Nodename: bookstore (nodetype: 1)

ຄູ່ມື Document ໂອລິຍາ