XML- tutoriaal

XML TUIS XML Inleiding XML Hoe om te gebruik XML-boom XML-sintaksis XML elemente XML-kenmerke XML Naamruimtes XML vertoon XML HttpRequest XML-ontleder XML DOM XML XPath XML XSLT XML XQuery XML XLink XML valideerder XML DTD XML-skema XML-bediener XML voorbeelde XML Vasvra XML-sertifikaat

XML AJAX

AJAX Inleiding AJAX XMLHttp AJAX-versoek AJAX-reaksie AJAX XML-lêer AJAX PHP AJAX ASP AJAX-databasis AJAX toepassings AJAX voorbeelde

XML DOM

DOM Inleiding DOM nodusse Toegang tot DOM DOM Node Info DOM Node Lys DOM deurkruis DOM Navigeer DOM Kry waardes DOM Verander nodusse DOM Verwyder nodes DOM vervang nodusse DOM Skep nodusse DOM Voeg nodes by DOM Kloon Nodes DOM Voorbeelde

XPath handleiding

XPath Inleiding XPath nodes XPath-sintaksis XPath-asse XPath-operateurs XPath voorbeelde

XSLT- tutoriaal

XSLT Inleiding XSL-tale XSLT-transformasie XSLT <sjabloon> XSLT <waarde-van> XSLT <vir-elk> XSLT <sorteer> XSLT <if> XSLT <kies> XSLT Pas toe XSLT op die kliënt XSLT op die bediener XSLT Wysig XML XSLT voorbeelde

XQuery- tutoriaal

XQuery Inleiding XQuery voorbeeld XQuery FLWOR XQuery HTML XQuery-bepalings XQuery-sintaksis XQuery Voeg by XQuery Kies XQuery-funksies

XML DTD

DTD Inleiding DTD Boublokke DTD Elemente DTD-kenmerke DTD Elements vs Attr DTD Entiteite DTD voorbeelde

XSD- skema

XSD Inleiding XSD Hoe om XSD <skema> XSD-elemente XSD-kenmerke XSD-beperkings

XSD -kompleks

XSD-elemente XSD leeg Slegs XSD-elemente Slegs XSD-teks XSD gemeng XSD-aanwysers XSD <enige> XSD <anyAttribute> XSD-vervanging XSD voorbeeld

XSD data

XSD-string XSD datum XSD Numeries XSD Diverse XSD-verwysing

Webdienste _

XML Dienste XML WSDL XML SEEP XML RDF XML RSS

Verwysings

DOM Node Tipes DOM Node DOM NodeLys DOM NamedNodeMap DOM-dokument DOM Element DOM-kenmerk DOM teks DOM CDATA DOM Kommentaar DOM XMLHttpRequest DOM-ontleder XSLT-elemente XSLT/XPath-funksies

XML DOM compareDocumentPosition() Metode


❮ Node Voorwerp

Voorbeeld

Die volgende kodefragment laai " books.xml " in xmlDoc en vergelyk die plasing van twee nodusse (die eerste en die derde <book>-element) in die DOM-hiërargie:

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);
}

Die afvoer van die kode hierbo sal wees:

4

Die meeste blaaiers sal leë spasies of nuwe reëls as teksnodes hanteer, IE 9 en vroeër sal nie. Dus, in die voorbeeld hierbo, sal die meeste blaaiers 4 uitvoer, terwyl IE 9 en vroeër 2 sal uitvoer.


Definisie en gebruik

Die compareDocumentPosition()-metode vergelyk die plasing van twee nodusse in die DOM-hiërargie (dokument).


Blaaierondersteuning

Internet Explorer Firefox Opera Google Chrome Safari

Die compareDocumentPosition()-metode word in alle groot blaaiers ondersteun.

Let wel: Internet Explorer 9 en vroeër ondersteun nie hierdie metode nie.


Sintaksis

nodeObject.compareDocumentPosition(node)

Grense

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

Terugkeerwaarde

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).

Tegniese besonderhede

DOM weergawe Kernvlak 3 Node-objek

❮ Node Voorwerp