• // Find node to delete var nodeToDelete = xml.documentElement.childNodes.item(1);
  • // Find node to move var nodeToMove = xml.documentElement.childNodes.item(1);
  • // Create a new Element node




    Download 2,96 Mb.
    Pdf ko'rish
    bet116/131
    Sana14.05.2024
    Hajmi2,96 Mb.
    #232039
    1   ...   112   113   114   115   116   117   118   119   ...   131
    Bog'liq
    Ceponkus, Hoodbhoy - Applied XML - Toolkit for Programmers

    // Create a new Element node.
    var newNode = xml.createElement("element2");
    // Insert the new Element node under the root element.
    xml.documentElement.insertBefore(newNode, null);
    // Display the resulting XML document
    alert(xml.xml);







    The resulting XML document appears as follows:




    Deleting Nodes
    This example takes the node we added from the previous example to get back to the 
    original XML document. The removeChild(...) method from the Node class is used to 
    delete the node.









    The resulting XML document appears as follows:



    Moving Nodes
    This example shows how to move nodes around in the tree. The appendChild(...) method 
    from the Node class is used to move element2 around. Of course, a combination of 
    removeChild(...) and insertBefore(...) could have been used to achieve the same result.





    Download 2,96 Mb.
    Pdf ko'rish