PHP Classes

append to xml

Recommend this page to a friend!

      Hierachical Data Object  >  All threads  >  append to xml  >  (Un) Subscribe thread alerts  
Subject:append to xml
Summary:trying to create a new xml file and append it to an existing one
Author:anthony greco
Date:2006-06-05 18:37:23


  1. append to xml   Reply   Report abuse  
Picture of anthony greco anthony greco - 2006-06-05 18:37:23
i'm slightly new to php and was wondering if you could help me with a problem i'm trying to solve. i want to be able to create a new xml file and then append it to an existing one. and i feel like i understand what to do but i'm not getting the results i expected. could anyone take a glance and tell me what i may be missing/misusing? most everything here is like the default test page for the Hierachical Data Object. here's my script:

<title>HDObj test page</title>
body {
background: #eeeeee;
h3 {
text-align: center;
th {
border: 1px solid black;
background: #aaaaaa;
td {
text-align: left;
vertical-align: top;
border: 1px solid black;
<h3>HDObj test page</h3>

function r_dump_errors(&$obj, $name="root") {
foreach ($obj->children as $child) {
r_dump_errors($obj->$child, $child);
if (!file_exists("data.xml")) {
die("no data.xml in ".dirname(__FILE__));
$fp = fopen("data.xml", "r");
$xml = fread($fp, filesize("data.xml "));

//these will be passed in through actionscript in the end, but for now i'm just manually declaring them...
$filename = "newFileName.jpg";
$caption = "newCaption";
$credit = "newCredit";

$foo = new HDObj("
<image>imageGallery/" . $filename . "</image>
<caption>" . $caption . "</caption>
<credit>" . $credit . "</credit>

$obj = new HDObj($xml);
$obj->append_xml($foo, 1);

print("hdobject's error log:<br>");

print("the newly created xml file to be appended:<br>");
print($foo->toXML(true, true));
file_put_contents("temp.xml", $obj->toXML(true, false), LOCK_EX);

print("and now the hdobject reconstructs xml from its structure:<br>");
$newxmlfile = $obj->toXML(true, true);


and you can view it here:

as i said, i'm slightly new to php so i apologize if this is a lame question. if there's anything else you may need to know, i'll be happy to get whatever info you might need.

thanks in advance.