Append to XML sheet with PHP
Posted: Wed Apr 16, 2008 5:59 pm
I have posted on multiple forums and also researched this online. I am having no luck. People just don't know it seems. Someone suggested I go here because you guys are the best, let's see if you are
because I have been working on this now for about a month, not the project, just this ONE thing.
This is for a CMS tool that does NOT use a DB. I decided to go with XML then. At first it was awesome. I am adding to the XML and it adds the content to the page with the corresponding pageid variable I have.
What if they need to add a page though? That's why I made this form.
I have this form
When they hit submit it needs to OPEN the EXISTING xml page (cms.xml) and APPEND the new content.
Here is my barebones xml sheet.
So when they hit submit the form passes the content to a newpage_submit.php and that makes variables from the form and then writes the XML. Right now I have this which WRITES the XML, but I can't make it APPEND the xml.
The str_replaces are because XML writer has an html entities function built in, so it converts all the HTML tags to HTML Unicode. Never mind that. Just how in the hell do I append a existing XML sheet! 
Also, after it appends the XML sheet can it create a new new HTML document with ++pageid so that it makes a new page with a new page id and so it pulls the XML data in i without manually having to go and create a new HTML document copy and pasting the template and adding the the pageid up one?
If anyone can just get me how to append data that would be awesome!
This is for a CMS tool that does NOT use a DB. I decided to go with XML then. At first it was awesome. I am adding to the XML and it adds the content to the page with the corresponding pageid variable I have.
What if they need to add a page though? That's why I made this form.
I have this form
Code: Select all
<form method="post" action="newpage_submit.php">
<input type="text" value="Title" name="title"/><br />
<input type="text" value="Sub Header" name="subheader" /><br />
<input type="text" value="Content Here" name="content"/><br />
<input type="submit" name="save" />
</form>
Here is my barebones xml sheet.
Code: Select all
<website>
<webpage>
<title></title>
<subhead></subhead>
<content>
<p></p>
</content>
</webpage>
</website>
Code: Select all
<?php
$newpage_title = $_POST['title'];
$newpage_subheader = $_POST['subheader'];
$newpage_content = $_POST['content'];
$newpage_content = str_replace("\r", "<br />", $newpage_content);
$xw = new xmlWriter();
$xw->openMemory();
//$xw->setIndent(true);
$xw->startElement('webpage');
$xw->writeElement ('title', $newpage_title);
$xw->writeElement('subhead', $newpage_subheader);
$xw->writeElement('content', $newpage_content);
$xw->endElement(); // webpage
$xw = $xw->outputMemory(true);
$xw = str_replace(' ', '', $xw);
$xw = str_replace('<', '<', $xw);
$xw = str_replace('>', '>', $xw);
?>
Also, after it appends the XML sheet can it create a new new HTML document with ++pageid so that it makes a new page with a new page id and so it pulls the XML data in i without manually having to go and create a new HTML document copy and pasting the template and adding the the pageid up one?
If anyone can just get me how to append data that would be awesome!