Try $nn = $xml->add_node("/root[1]", "node").  "root" is not a "full" XPath address.  "root[1]" is.  The only function that would allow you to enter "root" is evaluate(), and it returns you an array of paths.
 
So you could do:
$aArray = $xml->evaluate("/root");
$NewNodeFullPath = $add_xml->node($aArray[0], "node");
 
Nigel
===========================
For the most recent version of phpxml, V1.N.X, and an archive of this list visit:  http://www.sourceforge.net/projects/phpxmldb
----- Original Message -----
Sent: Thursday, September 06, 2001 3:31 AM
Subject: [phpXML] add_node problem

Hello all,
 
I'm trying to use PHPxml for working with XML document. Everyting works fine except adding the new nodes. Frankly speaking, method add_node doesn't work.
 
It returns path for the new node, but when I'm trying to get the results and show them or save it to file - I see NO new node that had been added.
 
Please take a look at my code:

<?
// Include the <phpXML/> class.
include("lib/xml.php");
 
// Create an XML object for the XML file.
$xml = new XML("some.xml");
 
$nn = $xml->add_node("/", "node");
$fp = fopen("some2.xml","w+");
// characters translation
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$xs = strtr($xml->get_file(), $trans);
// write
fputs($fp, $xs);
fclose($fp);
 
?>

file SOME.XML:
 
<?xml version="1.0" encoding="UTF-8"?>
<root/>

get_file methid returns original XML - simply <root/>. Note that I tried different variations of path parameter string in add_node method. (ie "root/", "/root", ".", "/", "/root/"... and so on)
 
When I 'm trying to get the path for the new created node I get a result - root/node[1]. But there no new node in the xml.
 
Please, can you explain me why this happens? Or maybe I'm using add_node not very correctly?
 
Serge.

Reply via email to