load("nodes.xml"); foreach ($dom->getElementsByTagName('node') as $node) $res[] = '"' . $node->getAttribute('name') . '"'; sort($res); return "new Array(" . join($res, ',') . ")"; } function findnode($name) { $dom = new domDocument; $dom->load("nodes.xml"); $found = 0; foreach ($dom->getElementsByTagName('node') as $node) if ($node->getAttribute('name') == $name) return array($dom, $node); return NULL; } function deletenode($arg) { $a = findnode($arg); if ($a != NULL) { $dom = $a[0]; $node = $a[1]; $node->parentNode->removeChild($node); $dom->save("nodes.xml"); } else { // oops } } function getnode($arg) { $a = findnode($arg); if ($a != NULL) { $node = $a[1]; $dom = new domDocument; $dom->appendChild($dom->importNode($node, true)); $dom->save("/tmp/foo.xml"); header("Content-type: text/xml"); return $dom->saveXML(); } else { return "not found"; // oops } } $handlers = array( 'nodelist' => nodelist, 'delete' => deletenode, 'get' => getnode, ); foreach ($handlers as $k => $v) if (array_key_exists($k, $_REQUEST)) { print $v($_REQUEST[$k]); break; } ?>