We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19975
    • 429 Posts
    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.
      Martin Sanders - Design & Web Development
      • 3749
      • 24,544 Posts
      Do you just want to display the RSS feed data, or are you looking to actually import it and create resources based on it?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 19975
        • 429 Posts
        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.
          Martin Sanders - Design & Web Development
          • 19975
          • 429 Posts
          Would it be possible to use getResources to import external data such a JSON?

          Is JSON quicker to parse than XML/RSS?
            Martin Sanders - Design & Web Development
            • 3749
            • 24,544 Posts
            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.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 19975
              • 429 Posts
              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.
                Martin Sanders - Design & Web Development
                • 3749
                • 24,544 Posts
                Are you talking simpleXML versus json_decode, or did you write your own parsers?
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 19975
                  • 429 Posts
                  I used simpleXML and json_decode PHP functions, as they seemed the easiest options for a PHP beginner wink

                    Martin Sanders - Design & Web Development
                    • 19975
                    • 429 Posts
                    $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);
                      Martin Sanders - Design & Web Development
                      • 3749
                      • 24,544 Posts
                      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.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting