1

What is correct "ECG-way" to load an remote XML file?

For local files this works:

$xml = new Varien_Simplexml_Config($configFile);
$node = $xml->getNode('my/selected/node');

But not from remote URL:

Varien_Simplexml_Config

public function __construct($sourceData=null) {
    if (is_null($sourceData)) {
        return;
    }
    if ($sourceData instanceof Varien_Simplexml_Element) {
       $this->setXml($sourceData);
    } elseif (is_string($sourceData) && !empty($sourceData)) {
        if (strlen($sourceData)<1000 && is_readable($sourceData)) {
            $this->loadFile($sourceData);
        } else {
            $this->loadString($sourceData);
        }
    }
    #$this->setCache(new Varien_Simplexml_Config_Cache_File());
    #$this->getCache()->setConfig($this);
}

Because $sourceData isn't readable it tries to load a XML string, what also doesn't work, because it's just the remote URL ...

Question: is there a method in Varien or Zend library that is usable for loading remote XML files?

0

You can try Varien_Http_Adapter_Curl but it's just a fancy way of doing a curl.

  • A workaround for a workaround? :) Seems to be a bit too much overhead, so i'll stay with file_get_contents() if there is nothing equivalent. – sv3n Jun 9 '17 at 17:13
-1

Another way would be to use Varien_Io_File and the read method:

public function read($filename, $dest=null)
{
    if (!is_null($dest)) {
        chdir($this->_cwd);
        $result = @copy($filename, $dest);
        chdir($this->_iwd);
        return $result;
    }

    chdir($this->_cwd);
    $result = @file_get_contents($filename);
    chdir($this->_iwd);

    return $result;
}
  • 1
    isn't this destined for local files? – Marius Jun 7 '17 at 7:09
  • @Marius with file_get_contents you can get whatever file you want – Raphael at Digital Pianism Jun 7 '17 at 7:16
  • I know I know...But I was wondering about it's moral :) – Marius Jun 7 '17 at 7:17
  • @Marius it's used in Mage_Paypal_Model_Report_Settlement in the fectchAndSave method to go to a specified host/path and fetch a report from there so I guess we're good ^^ – Raphael at Digital Pianism Jun 7 '17 at 7:18
  • I get the XML string, but with a PHP warning Warning: chdir(): No such file or directory (errno 2). Just to note Mage_Paypal_Model_Report_Settlement uses Varien_Io_Sftp ... – sv3n Jun 7 '17 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.