GetSimple Support Forum
xml data gets overwritten - Printable Version

+- GetSimple Support Forum (
+-- Forum: GetSimple (
+--- Forum: Developer Discussions (
+--- Thread: xml data gets overwritten (/showthread.php?tid=8742)

xml data gets overwritten - teazmo - 2016-09-23


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>');

$c_child $xml->addChild('category');

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

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



RE: xml data gets overwritten - jlyon1515 - 2016-09-23

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_settings simplexml_load_file($settingsFile);

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

Does that help?

RE: xml data gets overwritten - shawn_a - 2016-09-23

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);