GetSimple Support Forum

Full Version: write XML line by line
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone, this is my first post. Thanks for this great CMS and the community behind.

(english is not my mother language so, please, forget me for my poor spelling)

I use GIT for versioning my sites and the problem are the XMLs in one big line, so I decide break it tag by tag.

In admin/inc/caching_functions.php, at the end of file after saving the data:

Code:
$xml->asXML($filem);
    
    // PATCH XML line by line
    $tmpXMLfile = file_get_contents($filem);
    $tmpNTC = "###DONT_BREAK_CDADA###";
    
    // insert between the opening TAG and CDATA, and the closing too.
    $tmpXMLfile = str_replace("><![CDATA",">$tmpNTC<![CDATA",$tmpXMLfile);
    $tmpXMLfile = str_replace("]]></","]]>$tmpNTC</",$tmpXMLfile);
    
    // insert new line (linux) between ><
    $tmpXMLfile = str_replace("><",">\n<",$tmpXMLfile);
    
    // clean DONT_BREAK_CDATA and write the file again.
    $tmpXMLfile = str_replace("$tmpNTC","",$tmpXMLfile);
    file_put_contents($filem,$tmpXMLfile);



Now, every change made with de admin panel will write XMLs TAGs separated by lines and can be follow the diffs with GIT or another version control system.

I hope this will be useful to somebody.

Best.
Would you like to also post this as an issue on the GetSimple Github repository? Perhaps even fork the project and make a pull request for the change?
(2015-08-12, 03:45:05)Angryboy Wrote: [ -> ]Would you like to also post this as an issue on the GetSimple Github repository? Perhaps even fork the project and make a pull request for the change?

Thanks, I will do soon.
You could just use the aftersave hooks to post process it
Expanding on what shawn said (if almendro wants to write it as a plugin and publish it to extend):

PHP Code:
<?php
// plugins/prettify_pagecache.php
// Register the plugin
register_plugin(/*  registration details */);

// Add the page saving hook
add_action('pagecache-aftersave''prettify_pachecache');

// Define the prettifying function
function prettify_pachecache() {
 
 // get the xml file ($filem) and then run almendro's prettifying script


I still think almendro's suggestion is worth making an issue/pull request on (e.g. having a constant in gsconfig.php that enables/disables xml prettifying).
Nope I'll add a filter instead
even better
Added in to core
AND added a filter

https://github.com/GetSimpleCMS/GetSimpl...ssues/1089
Nicely done!
Wow, this is so fast. Thanks dudes! I'm glad to see this was happened.

Best!
(2015-08-13, 04:03:26)shawn_a Wrote: [ -> ]even better
Added in to core
AND added a filter

https://github.com/GetSimpleCMS/GetSimpl...ssues/1089

an honor to contribute into the CORE! thanks. Big Grin
Thanks for the suggestion, this would have actually saved me a ton of time last week, I had my text editor refreshing and reformatting constantly so i could read a file, was very annoying while i was testing output of something.

Always do a backup before testing a beta feature, hopefully it wont break anything but since it modifies all xml it could.
Needs testing with entities and utf-8, my tests seemed to be ok so far.