AW: change Position of a Node
Brought to you by:
bs_php,
nigelswinson
|
From: J. C. <jan...@im...> - 2004-07-26 13:16:48
|
Hi
my problem is solved.
The code now looks like the following, maybe it can help also someone else.
Cheers
Jan
require_once("include/XPath.class.php");
$xpath=new XPath($f_dir.$file."_web.xml");
/*
..$xpath=new XPath();
..$xpath->setSkipWhiteSpaces();
..$xpath->importFromFile($f_dir.$file."_web.xml");
*/
// ACTIONS:
if(isset($_POST["aktion"])){
..$path=$_POST["lokation_id"];
..$target_path=$_POST["target_path"];
..switch($_POST["aktion"]){
....case "DEL":
......$xpath->removeChild($path,true);
......$pos=strrpos($path,"/");
......$path=substr($path,0,$pos);
......break;
....case "NEW":
......if ($_POST["exelmode"]=="true"){
........//Insert Nodes from List in Textarea
........$namen=split("\r\n",$_POST["atarea"]);
........$first=true;
........foreach($namen as $name){
..........if ($name=="") continue;
..........if($first){
............$path_temp=$xpath->appendChild($path,"<data
name=\"".$name."\">".$_POST["text_entry"]."</data>");
............$first=false;
..........}else
............$xpath->appendChild($path,"<data
name=\"".$name."\">".$_POST["text_entry"]."</data>");
........}
........$path=$path_temp;
......}else
........//normal new entry
........$path=$xpath->appendChild($path,"<data
name=\"".$_POST["bezeichnung"]."\">".$_POST["text_entry"]."</data>");
......break;
....case "EDIT":
......$xpath->setAttribute($path,"name",$_POST["bezeichnung"]);
......$xpath->replaceData($path,$_POST["text_entry"]);
......break;
....case "CLONE":
......$clonedNode=&$xpath->cloneNode($path,FALSE);
......$xpath->insertBefore($path, $clonedNode,true,true);
......break;
....case "PASTE_INTO":
......$clonedNode=&$xpath->cloneNode($target_path,FALSE);
......$path_temp=$xpath->appendChild($path, $clonedNode, FALSE, TRUE); //
insert here
......break;
....case "UP":
......$clonedNode=&$xpath->cloneNode($path,FALSE); // -> duplicate
......$xpath->removeChild($path, FALSE); // -> take away
......$xpath->insertBefore($target_path, $clonedNode, FALSE, TRUE); //
insert here
......$path=$target_path;
......break;
....case "DOWN":
......if ($_POST["toolkit"]=="append"){ // node append to parent node (it is
the last element)
........$clonedNode=&$xpath->cloneNode($path,FALSE); // -> duplicate
........$path_temp=$xpath->appendChild($target_path, $clonedNode, FALSE,
TRUE); // insert here
........$xpath->removeChild($path, TRUE); // -> take away
........$pos1=strrpos($path_temp,"[");
........$pos2=strrpos($path_temp,"]")-1;
........$pos=substr($path_temp,$pos1+1,strlen($path_temp)-$pos2);
........$path=substr($path_temp,0,$pos1)."[".($pos-1)."]";
......}else{
........$clonedNode=&$xpath->cloneNode($target_path,FALSE); // -> duplicate
........$xpath->removeChild($target_path, FALSE); // -> take away
........$xpath->insertBefore($path, $clonedNode, FALSE,TRUE); // insert here
........$path=$target_path;
......}
......break;
..}
..copy($f_dir.$file."_web.xml",$f_dir.time()."_".$file."_web.xml");
..$xpath->exportToFile($f_dir.$file."_web.xml",'','<?xml version="1.0"
encoding="iso-8859-1"'.'?'.'>');
}
> -----Ursprungliche Nachricht-----
> Von: php...@li...
> [mailto:php...@li...]Im Auftrag von J.
> Carmanns
> Gesendet: Mittwoch, 21. Juli 2004 15:29
> An: php...@li...
> Betreff: change Position of a Node
>
>
> Can anyone show me a smart way to move a complete node-structure
> up or down
> in the xml document?
>
> $xml="<root><A>abc</A><B>def</B></root>";
> ...
> move("/root/B[1]","up");
> echo $xml; //should give: <root><B>def</B><A>abc</A></root>
>
> move("/root/B[1]","down");
> echo $xml; //should give: <root><A>abc</A><B>def</B></root>
>
> function move($xpath,$direction){
> global $XPathObject;
> //???
> }
>
> I am thinking about deleting and re-inserting all the nodes in the parent
> node but there must be an easy way, or not? Can I just change the
> two index
> keys in the xpath array?
>
> Has anyone coded something for this problem before?
>
> Thanks for any help!
>
> Cheers
> Jan
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by BEA Weblogic Workshop
> FREE Java Enterprise J2EE developer tools!
> Get your free copy of BEA WebLogic Workshop 8.1 today.
> http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
> _______________________________________________
> Phpxpath-users mailing list
> Php...@li...
> https://lists.sourceforge.net/lists/listinfo/phpxpath-users
|