I have been experimenting with third party booking systems for a number of property relates sites (I seem to be building a trend :S) and need to pull data from RSS/XML/Json feeds into MODX. I have previously developed basic parsing scripts using xpath with some success. However I am looking for a more efficient way of importing data to reduce server response times for a new dev project.
I would like to hear any suggestions as to existing scripts which may offer a higher level of optimisation and provide a more generic approach. I have already tested getFeed and was unimpressed (no disrespect to dev) with the server load and performance. The core code now seems quite dated which may account for slow server response times on testing.
The SIMPLX Widgeteer seems to be a new release but I have been unable to see many active users testing and providing forum feedback.
Do you just want to display the RSS feed data, or are you looking to actually import it and create resources based on it?
Hi Bob,
As data will be continually updated via individual owners/subscribers via a booking system I am only looking to pass data through MODX templates and retain information within the original third-party database admin.
I would like to use MODX caching, templates etc to increase speed and provide a tighter integration.
Would it be possible to use getResources to import external data such a JSON?
Is JSON quicker to parse than XML/RSS?
I can't think of a way to use getResources on remote data.
I do think JSON would be slightly faster (and easier, imo). Parsing XML is more complex and I think you'd be transferring more data with XML because of the tags. XML might be better if you'll be getting data from multiple remote sources with different formats, especially if the data items will vary a lot in structure.
I have developed a parser to process the same data via Json and RSS (for testing) and return the same chunk + placeholders for both feeds and can confirm that there is no difference in performance (for my project).
Json could be better for larger projects due to slimmer syntax.
Are you talking simpleXML versus json_decode, or did you write your own parsers?
I used simpleXML and json_decode PHP functions, as they seemed the easiest options for a PHP beginner
$json_a=json_decode(file_get_contents(URL TO RSS PATH),true);
$feed_a = $json_a[channel][$v];
foreach ($feed_a as $key => $val) {
$modx->setPlaceholder($key, $val);
foreach ($val as $cKey => $cVal ) {
foreach ($cVal as $gcKey => $gcVal ) {
$modx->setPlaceholder($key . '_' . $gcKey, $gcVal);
}
}
$v++;
}
$output .= $modx->parseChunk($tpl, $modx->setPlaceholders, '[[+', ']]');
return ($output);
VS
$XML = new DOMDocument();
$XML->load(URL TO RSS PATH);
$xpath = new DOMXPath($XML);
$i = 1;
foreach ($xpath->query("//channel/item[$i]") as $node) {
foreach ($xpath->query("//channel/item[$i]/*") as $node) {
$modx->setPlaceholder($node->nodeName, $node->nodeValue);
}
$output .= $modx->parseChunk($tpl, $modx->setPlaceholders, '[[+', ']]');
$i++;
}
return ($output);
Interesting, my gut feeling was that json_decode would be faster. How many iterations did you run?
There would have to be a slight advantage to JSON when fetching the file with cURL, but it would be tiny.