> I am new to phpxml and trying to implement a PHP / XML CSM system. I
> cant seem to get some of the methods to work, no matter how hard I
> try. And I don't seem to get any helpful error msgs. I have gone
> through everything I can find on the internet about phpxml, but I cant
> find any examples of some methods being used (for example add_node,
> remove_node, set_content etc). I was wondering if you have any real
> world examples of how these methods being used, or know where I could
> find any? if anybody can point me to some sources of a working system
> that uses these and other methods, especially to edit and write XML
> files I would really be pleased.
If you are new to phpxml, then the problem is probably that you are trying to use add_node, remove_node, etc with a $context parameter that is not a "Full path of the parent".  If you pass "//Element" instead of "/Root[1]/Element[4]" then the call isn't going to work.  In general you need to use evaluate() in order to get an array of "Full paths" that you then use with each of the other functions.  You can't just use the other functions with any old XPath expression, even if it would evaluate to only one node.
As for examples and documentation, the most recent documentation is the stuff that ships with phpxml 1.0.  Also at: http://www.phpxml.org/scripts/documentation/ but there is a more recent version of the class, available at http://sourceforge.net/projects/phpxmldb/ as 1.N.X releases.  I'm still waiting and hoping for "approval" from Michael for this "fork" so that it can be considered 1.X releases not 1.N.X releases.  I have no immediate plans to update the html documentation, but will continue to commit to the source documentation.  The release notes describe the changes.
If anyone wants to volunteer to take on the task of maintaining the html documentation given the comments in the 1.N.X releases, then that would be great.  :o)
Examples wise the best I can offer is the phpxmldb project, that is built upon the phpxml work also, not surprisingly, available from http://sourceforge.net/projects/phpxmldb/ The code is well documented, and might help you with how to use the phpxml class.  As a short example below is the private AddRecord function that shows use of add_node() and add_content() functions.
I hope that this post helps [EMAIL PROTECTED] and [EMAIL PROTECTED] with their request too.

 // Internal version of AddRecord. 
 function _AddRecord($TableTag, $RecordTag, $aElementData) {
  // If you are having difficulty using this function.  Then set this to true and
  // you'll get diagnostic info displayed to the output.
  $bDebugThisFunction = false;
  if ($bDebugThisFunction) {
   $aStartTime = $this->BeginDebugFunction("AddRecord");
   echo "TableTag: $TableTag\n";
   echo "RecordTag: $RecordTag\n";
   echo "ElementData:\n";
  // Numpty check
  if (!$TableTag || !$RecordTag) {
   trigger_error("The TableTag and RecordTag arguments must have a value.");
   return false;
  // Get the table path, creating the table if it doesn't exist.
  $TablePath = $this->_FindTable($TableTag, true);
  // Obtain a new record id.
  $NewRecordId = $this->_GetNewRecordId($TablePath);
  if ($bDebugThisFunction) echo "New record id is $NewRecordId\n";
  // Add the record
  if ($bDebugThisFunction) echo "Adding new record at $TablePath\n";
  $RecordPath = $this->XmlDb->add_node($TablePath, $RecordTag);
  $this->XmlDb->add_attributes($RecordPath, array("created" => $this->GetDbTime(), "RecordId" => $NewRecordId));
  if ($bDebugThisFunction) echo "New record now at $RecordPath\n";
  // Add the content.
  foreach($aElementData as $Name => $Value) {
   $EntryPath = $this->XmlDb->add_node($RecordPath, "$Name");
   if ($bDebugThisFunction) echo "Added new entry $EntryPath\n"; 
   // Prepare the value by stripping \r's and calling htmlspecialchars.
   $Value = htmlspecialchars($Value);
   $Value = str_replace("\r", "", $Value);
   $this->XmlDb->add_content($EntryPath, $Value);
   if ($bDebugThisFunction) echo "Added new content to $EntryPath: ".$this->XmlDb->get_content($EntryPath)."\n"; 
  if ($bDebugThisFunction) echo "\n";
  $bResult = true;
  if ($bDebugThisFunction) $this->CloseDebugFunction($aStartTime, $bResult);
  return $bResult;


Reply via email to