RemoveChild Problem
Brought to you by:
bs_php,
nigelswinson
From: Jan C. <ja...@ca...> - 2001-11-30 23:26:41
|
Hi all, I am really fighting with this - it only removes "stand alone" childs and not multiple child-nodes of a node: The XML (List of birthdays per month) - (short version): <DATA> <MON07> <geburtstag> <datum>1007124449</datum> <name>asdasd</name> <tag>9</tag> </geburtstag> </MON07> <MON09> <geburtstag> <datum>1007124458</datum> <name>Jan</name> <tag>8</tag> </geburtstag> </MON09> <MON10> <geburtstag> <datum>1007124443</datum> <name>hgvghv</name> <tag>9</tag> </geburtstag> <geburtstag> <datum>1007124467</datum> <name>adsd</name> <tag>9</tag> </geburtstag> </MON10> </DATA> Now I like to delete all "geburtstag" entries which are selected by checkboxes - the value "datum" is posted by "HTTP_POST_VARS" of the checkboxes and used to indentify the individual entries: //Start as usual: $xpath_del = new XPATH($xmlfile); $path = $xpath_del->evaluate("/*/*/geburtstag"); foreach( $path as $value ) { //Get the "datum" node value in the xml $date = $xpath_del->getData($value."/datum[1]"); //Compare the "datum" with the values in the HTTP_POST_VARS array if (array_search ($date,$HTTP_POST_VARS)!="") { //Ok - this "value" node has too be deleted: echo "Now comes: ".$value."<hr>"; $xpath_del->removeChild($value); echo "Deleted<hr>"; } } I get this output result: __________________________________________________________ Now comes: /DATA[1]/MON07[1]/geburtstag[1] ---------------------------------------------------------------------------- ---- Deleted ---------------------------------------------------------------------------- ---- Now comes: /DATA[1]/MON09[1]/geburtstag[1] ---------------------------------------------------------------------------- ---- Deleted ---------------------------------------------------------------------------- ---- Now comes: /DATA[1]/MON10[1]/geburtstag[1] ---------------------------------------------------------------------------- ---- Warning: Undefined index: /DATA[1]/MON10[1]/geburtstag[1]/datum in E:\imeso\web\portal\data\xpath.class.php on line 1222 Warning: Undefined index: /DATA[1]/MON10[1]/geburtstag[1]/name in E:\imeso\web\portal\data\xpath.class.php on line 1222 Warning: Undefined index: /DATA[1]/MON10[1]/geburtstag[1]/tag in E:\imeso\web\portal\data\xpath.class.php on line 1222 Deleted ---------------------------------------------------------------------------- ---- Now comes: /DATA[1]/MON10[1]/geburtstag[2] ---------------------------------------------------------------------------- ---- Warning: Undefined index: geburtstag[2] in E:\imeso\web\portal\data\xpath.class.php on line 1098 Deleted ---------------------------------------------------------------------------- ---- Now comes: /DATA[1]/MON11[1]/geburtstag[1] ---------------------------------------------------------------------------- ---- Warning: Undefined index: /DATA[1]/MON11[1]/geburtstag[1]/datum in E:\imeso\web\portal\data\xpath.class.php on line 1222 Warning: Undefined index: /DATA[1]/MON11[1]/geburtstag[1]/name in E:\imeso\web\portal\data\xpath.class.php on line 1222 __________________________________________________________ and so on ..... Can anyone help me with this??? Thanks a lot!!! Cheers Jan |