# Snippet to read and parse XML input # USAGE: [[!xmlparser? &source=`feed.rss` &tpl=`xmlTpl`]] $modx->setDebug(true); $source = $scriptProperties['source']; if (empty($source)) { $modx->log(modX::LOG_LEVEL_DEBUG,'[xmlparser] Empty source adress passed, aborting.'); return ''; } else { if ($xml = simplexml_load_string(file_get_contents($source))) { $output = ''; foreach ($xml->channel->item as $item) { foreach ($item->children() as $key => $value) { if ($key == 'pubDate') { $value = strftime("%d.%m.%Y %H:%M:%S", strtotime($value)); } $modx->setPlaceholder($key, $value); foreach ($item->$key->attributes() as $attrkey => $attrval) { $modx->setPlaceholder($key.'.'.$attrkey, $attrval); } } $output .= $modx->getChunk($scriptProperties['tpl']); } } else { exit('Konnte '.$source.' nicht öffnen.'); } return $output; }
<h4><a href="[[+link]]" title="[[+title]]">[[+title]]</a></h4> <p><b>[[+pubDate:default=``]]</b></br> [[+locationname:default=``]]</br> [[+eventdate:default=``]][[+description:default=``]] <img src="[[+enclosure.url]]"></p>
<enclosure url="some.url">
# Snippet to read and parse XML input # USAGE: [[!parsex? &source=`feed.rss` &tpl=`xmlTpl`]] # author: [email protected] //$modx->setDebug(true); $source = $modx->getOption('source', $scriptProperties, 'http://modx.com/feeds/latest.rss'); $element = $modx->getOption('element', $scriptProperties, 'item'); $tpl = $modx->getOption('tpl', $scriptProperties, 'xmlTpl'); $wrapper = $modx->getOption('wrapper', $scriptProperties, 'wrapX'); $debugmode = $modx->getOption('debugmode', $scriptProperties, false); if (empty($source)) { $modx->log(modX::LOG_LEVEL_ERROR,'[parseX] Empty source adress passed, aborting.'); return 'No source definded.'; } else { if ($xml = simplexml_load_string(file_get_contents($source))) { #$modx->log(modX::LOG_LEVEL_ERROR,'[parseX] can read file: '.$source); #$modx->log(modX::LOG_LEVEL_ERROR,'[parseX] element value '.$element); $nodes = $xml->xpath("//$element"); foreach ($nodes as $node) { $values = array(); foreach ($node as $key => $value) { if ($key == 'pubDate') { $value = strftime("%d.%m.%Y %H:%M:%S", strtotime($value)); } $values[$key] = (string)$value; foreach ($node->$key->attributes() as $attrkey => $attrval) { $values[$key.'.'.$attrkey] = (string)$attrval; } } if ($debugmode==true) { var_dump($values); } $output .= $modx->getChunk($tpl, $values); } } else { $modx->log(modX::LOG_LEVEL_ERROR,'[parseX] can NOT read file: '.$source); } $result = array("result" => $output); return $modx->getChunk($wrapper, $result); }
<IRXML><Errors><Error errorCode="0">This request failed validation. Type of Failure encountered was Unauthorized</Error></Errors><IPAddress>94.134.81.11</IPAddress><RequestedUrl>http://xml.corporate-ir.net:84/irxmlclient.asp?compid=251258&reqtype=newsreleases_2</RequestedUrl></IRXML>
<NewsRelease ReleaseID="2047271" DLU="20150512 21:00:31" ArchiveStatus="Current" RNSSource="" ContainerId="" Type="2"><Title>GasLog Ltd. Announces Election of Directors at 2015 Annual General Meeting of Shareholders</Title> <ExternalURL/> <Date Date="20150512" Time="17:00:31" TimeZone="ET">5/12/2015 5:00:31 PM</Date> <DisplayDateStart Date="20150512" Time="17:00:31">May 12 2015 05:00</DisplayDateStart> <DisplayDateEnd Date="20350512" Time="21:00:31">May 12 2035 09:00</DisplayDateEnd> <ContentNetworkingLinks/> <Categories> <Category>NA</Category> </Categories> </NewsRelease>
Can access the feed, i get the following error:
<irxml><errors><error errorcode="0">This request failed validation. Type of Failure encountered was Unauthorized</error></errors><ipaddress>94.134.81.11</ipaddress><requestedurl>http://xml.corporate-ir.net:84/irxmlclient.asp?compid=251258&reqtype=newsreleases_2</requestedurl></irxml>
# Snippet to read and parse XML input # USAGE: [[!parsex? &source=`feed.rss` &tpl=`xmlTpl`]] # author: [email protected] //$modx->setDebug(true); $source = $modx->getOption('source', $scriptProperties, 'http://modx.com/feeds/latest.rss'); $element = $modx->getOption('element', $scriptProperties, 'item'); $tpl = $modx->getOption('tpl', $scriptProperties, 'xmlTpl'); $wrapper = $modx->getOption('wrapper', $scriptProperties, 'wrapX'); $limit = $modx->getOption('limit', $scriptProperties, 0); $debugmode = $modx->getOption('debugmode', $scriptProperties, false); if (empty($source)) { $modx->log(modX::LOG_LEVEL_ERROR,'[parseX] Empty source adress passed, aborting.'); return 'No source definded.'; } else { if ($xml = simplexml_load_string(file_get_contents($source))) { #$modx->log(modX::LOG_LEVEL_ERROR,'[parseX] can read file: '.$source); #$modx->log(modX::LOG_LEVEL_ERROR,'[parseX] element value '.$element); $nodes = $xml->xpath("//$element"); $nodecount = 0; foreach ($nodes as $node) { $nodecount++; $values = array(); foreach ($node as $key => $value) { if ($key == 'pubDate') { $value = strftime("%d.%m.%Y %H:%M:%S", strtotime($value)); } $values[$key] = (string)$value; foreach ($node->$key->attributes() as $attrkey => $attrval) { $values[$key.'.'.$attrkey] = (string)$attrval; } } if ($debugmode==true) { var_dump($values); } $output .= $modx->getChunk($tpl, $values); if (($nodecount >= $limit) && ($limit !=0)) break; } } else { $modx->log(modX::LOG_LEVEL_ERROR,'[parseX] can NOT read file: '.$source); } $result = array("result" => $output); return $modx->getChunk($wrapper, $result); }
[[+NewsRelease.ReleaseID]]