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
Messages:1
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:

<html>
<head>
<title>HDObj test page</title>
<style>
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;
}
</style>
</head>
<body>
<h3>HDObj test page</h3>
<?php
include_once("hdobj.php");

function r_dump_errors(&$obj, $name="root") {
$obj->dump_errors();
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 "));
fclose($fp);

//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("
<temp>
<pic>
<image>imageGallery/" . $filename . "</image>
<caption>" . $caption . "</caption>
<credit>" . $credit . "</credit>
</pic>
</temp>");

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

print("hdobject's error log:<br>");
$obj->dump_errors();

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

?>
</body>
</html>


and you can view it here: http://senatorslab.kicks-ass.net/testBed/hdObj/my_test_hdobj.php

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.