Created
April 1, 2020 10:17
-
-
Save alexey-kar/280473854f08119a9a5903ec5712dbf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/questions/16412047/parse-xml-namespaces-with-php-simplexml | |
<?php | |
$data = "http://alerts.weather.gov/cap/tx.php?x=1"; | |
$entries = file_get_contents($data); | |
$entries = new SimpleXmlElement($entries); | |
if(count($entries)): | |
//echo "<pre>";print_r($entries);die; | |
//alternate way other than registring NameSpace | |
//$asin = $asins->xpath("//*[local-name() = 'ASIN']"); | |
$entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); | |
$result = $entries->xpath("//prefix:entry"); | |
//echo count($asin); | |
//echo "<pre>";print_r($result);die; | |
foreach ($result as $entry): | |
//echo "<pre>";print_r($entry);die; | |
$dc = $entry->children('urn:oasis:names:tc:emergency:cap:1.1'); | |
echo $dc->event."<br/>"; | |
echo $dc->effective."<br/>"; | |
echo "<hr>"; | |
endforeach; | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment