Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
xml data gets overwritten
#1
Hello,

So far I've created my own very simple plugin. It has got a form to fill in a title or in this case a category and an overview of all titles.

After submitting the title with my form the data gets saved to my xml-file. So far thats fine, but when I try to add another new entry the previous data gets overwritten.

I added following function to my plugin class called 'helloworld' Big Grin 


PHP Code:
public function processData($edit=null){

$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><channel></channel>');

if(isset(
$_POST['new_category']))
{
$c_child $xml->addChild('category');
$c_child->addAttribute('name'$_POST['title']);
}
if(
XMLsave($xmlHelloWorldFile))

{
echo 
'<div class="updated">Updated!</div>';


How can I 'add' new data to the existing xml-data?

Thanks

teazmo
Reply
#2
Quote:
PHP Code:
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><channel></channel>'); 

How can I 'add' new data to the existing xml-data?

Maybe I'm not reading your question right, but it seems to me that you need to change the line that I quoted above. You're making the file from scratch every time according to that line.

Do something like:

PHP Code:
$settingsFile=GSDATAOTHERPATH .'helloworld.xml';

if (
file_exists($settingsFile)) {
    
$xml_settings simplexml_load_file($settingsFile);
} else {
    
$xml = @new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><channel></channel>');
    
$xml->asXML($uriRedirectFile);
    
$xml_settings simplexml_load_file($settingsFile);


Then you can do your $xml_settings->addChild('category');

Does that help?
Reply
#3
check theme.php for example
You want to load the xml ( if exist ) then modify nodes

If exist you can just get the xml from file, or create it node by node if not.

PHP Code:
    $xml getXML($path $file); 
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply




Users browsing this thread: 1 Guest(s)