XML Tutorial

XML หน้าแรก บทนำ XML XML วิธีใช้งาน XML Tree ไวยากรณ์ XML องค์ประกอบ XML คุณสมบัติ XML XML เนมสเปซ จอแสดงผล XML XML HttpRequest XML Parser XML DOM XML XPath XML XSLT XML XQuery XML XLink เครื่องมือตรวจสอบ XML XML DTD XML Schema XML Server ตัวอย่าง XML แบบทดสอบ XML ใบรับรอง XML

XML AJAX

บทนำ AJAX AJAX XMLHttp คำขอ AJAX การตอบสนอง AJAX ไฟล์ AJAX XML AJAX PHP AJAX ASP ฐานข้อมูล AJAX แอปพลิเคชัน AJAX ตัวอย่าง AJAX

XML DOM

บทนำ DOM โหนด DOM การเข้าถึง DOM ข้อมูลโหนด DOM รายการโหนด DOM DOM Traversing การนำทาง DOM DOM รับค่า DOM เปลี่ยนโหนด DOM ลบโหนด DOM แทนที่โหนด DOM สร้างโหนด DOM เพิ่มโหนด DOM โคลนโหนด ตัวอย่าง DOM

บทช่วย สอนXPath

บทนำ XPath โหนด XPath ไวยากรณ์ XPath แกน XPath ตัวดำเนินการ XPath ตัวอย่าง XPath

กวดวิชาXSLT

บทนำ XSLT ภาษา XSL การแปลง XSLT XSLT <แม่แบบ> XSLT <ค่าของ> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <เลือก> ใช้ XSLT XSLT บนไคลเอนต์ XSLT บนเซิร์ฟเวอร์ XSLT แก้ไข XML ตัวอย่าง XSLT

กวดวิชาXQuery

บทนำ XQuery ตัวอย่าง XQuery XQuery FLWOR XQuery HTML ข้อกำหนด XQuery ไวยากรณ์ XQuery XQuery เพิ่ม XQuery Select ฟังก์ชัน XQuery

XML DTD

บทนำ DTD บล็อกตัวต่อ DTD องค์ประกอบ DTD คุณสมบัติ DTD องค์ประกอบ DTD เทียบกับ Attr หน่วยงาน DTD ตัวอย่าง DTD

ส คีมา XSD

บทนำ XSD XSD วิธีการ XSD <schema> องค์ประกอบ XSD แอตทริบิวต์ XSD ข้อจำกัด XSD

XSD Complex

องค์ประกอบ XSD XSD ว่างเปล่า องค์ประกอบ XSD เท่านั้น XSD Text เท่านั้น XSD ผสม ตัวชี้วัด XSD XSD <ใด ๆ> XSD <anyAttribute> การทดแทน XSD XSD ตัวอย่าง

ข้อมูลXSD

XSD สตริง วันที่ XSD XSD ตัวเลข XSD เบ็ดเตล็ด ข้อมูลอ้างอิง XSD

บริการเว็บ

XML Services XML WSDL XML SOAP XML RDF XML RSS

อ้างอิง

ประเภทโหนด DOM โหนด DOM DOM NodeList DOM NamedNodeMap เอกสาร DOM องค์ประกอบ DOM แอตทริบิวต์ DOM ข้อความ DOM DOM CDATA ความคิดเห็นของ DOM DOM XMLHttpRequest DOM Parser องค์ประกอบ XSLT ฟังก์ชัน XSLT/XPath

XML DOM เปรียบเทียบDocumentPosition() Method


❮ วัตถุโหนด

ตัวอย่าง

โค้ดย่อยต่อไปนี้โหลด " books.xml " ลงใน xmlDoc และเปรียบเทียบตำแหน่งของสองโหนด (องค์ประกอบ <book> ที่หนึ่งและที่สาม) ในลำดับชั้น DOM:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();

function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName('book')[0];
    var y = xmlDoc.getElementsByTagName('book')[2];
    document.getElementById("demo").innerHTML =
    x.compareDocumentPosition(y);
}

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

4

เบราว์เซอร์ส่วนใหญ่จะถือว่าช่องว่างสีขาวหรือบรรทัดใหม่เป็นโหนดข้อความ IE 9 และรุ่นก่อนหน้าจะไม่ทำ ในตัวอย่างข้างต้น เบราว์เซอร์ส่วนใหญ่จะส่งออก 4 ในขณะที่ IE 9 และรุ่นก่อนหน้าจะออก 2


ความหมายและการใช้งาน

วิธี CompareDocumentPosition() จะเปรียบเทียบตำแหน่งของสองโหนดในลำดับชั้น DOM (เอกสาร)


รองรับเบราว์เซอร์

Internet Explorer Firefox โอเปร่า Google Chrome ซาฟารี

วิธี CompareDocumentPosition() ได้รับการสนับสนุนในเบราว์เซอร์หลักทั้งหมด

หมายเหตุ: Internet Explorer 9 และรุ่นก่อนหน้าไม่รองรับวิธีนี้


ไวยากรณ์

nodeObject.compareDocumentPosition(node)

พารามิเตอร์

Parameter Type Description
node Node object Required. Specifies the node to compare with the current node

คืนมูลค่า

Type Description
Number A Number representing where the two nodes are positioned compared to each other. The possible return values are:

1 - No relationship, the two nodes do not belong to the same document.

2 - The specified node precedes the current node.

4 - The specified node follows the current node.

8 - The specified node contains the current node.

16 - The specified node is contained by the current node.

32 - The specified and the current node have no common container node or the two nodes are different attributes of the same node.

Note: The return value could also be a combination of values. E.g. a return value of 20 means that the specified node is contained by the current node (16) AND the specified node follows the current node (4).

รายละเอียดทางเทคนิค

เวอร์ชัน DOM วัตถุโหนดระดับ 3 หลัก

❮ วัตถุโหนด