Example #1
0
    $xml->formatOutput = true;
    $xml->preserveWhiteSpace = false;
    $xml->loadXML($str) or die("Error");
    return $xml;
}
// a function to replace a node in the XML tree, given the DOM Object,
// the tag name to use, the new text value, the parent node and the current node
function replaceNode($xml, $tagName, $textValue, $parentNode, $nodeToReplace)
{
    $newNode = $xml->createElement("{$tagName}");
    $newTextNode = $xml->createTextNode("{$textValue}");
    $newNode->appendChild($newTextNode);
    $parentNode->replaceChild($newNode, $nodeToReplace);
}
$xml = getXML("notes.xml");
// get document element
$root = $xml->documentElement;
//collection
$notes = $root->childNodes->item(3);
//notes
// find the note to edit
foreach ($notes->childNodes as $note) {
    if ($note->getAttribute('id') == $noteID) {
        // replace the status node with the new value
        replaceNode($xml, "status", $newStatus, $note, $note->childNodes->item(6));
        $status = $note->childNodes->item(6);
        // save the changes
        $xml->save("notes.xml");
        echo "Note status has been updated to " . $status->nodeValue;
    }
}
Example #2
0
     } else {
         if ($copydrag == 1) {
             if ($recursive == 1) {
                 recursiveCopy($dragID, $dropID);
                 $okDrop = true;
                 $msg = 'Tout est ok';
             } else {
                 //copy du noeud
                 $result = copyNode($dragID, $dropID);
                 $okDrop = $result[0];
                 $msg = $result[1];
                 log_phantom($result[1], "Copie du noeud" . $dragID);
             }
         } else {
             if ($replace == 1) {
                 replaceNode($dropID, $dragID);
                 $okDrop = true;
                 $msg = 'Tout est ok';
             } else {
                 //déplacement standard
                 if ($hitMode == "over") {
                     $okDrop = moveNode($dragID, $dropID);
                 } else {
                     $okDrop = moveCrossNode($dragID, $dropID);
                 }
                 $msg = 'Tout est ok';
                 log_phantom($dragID, "Déplacement du noeud");
             }
         }
     }
 }