-
-
Save micheee/ca015c4f81f8c7c25f53 to your computer and use it in GitHub Desktop.
Namespaces with simplexml
This file contains 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
<?php | |
$str = <<<EOD | |
<emp> | |
<name>Peter</name> | |
<category name="Employee" label="Mitarbeiter"/> | |
<xy:gender>Male</xy:gender> | |
<xy:website xy:href="http://www.xyz.com/peter">Peter's Homepage</xy:website> | |
</emp> | |
EOD; | |
$xmlObj = simplexml_load_string($str,'SimpleXMLElement', LIBXML_NOWARNING | LIBXML_NOXMLDECL | LIBXML_NOERROR); | |
$xmlObj->registerXPathNamespace('xy','http://myapp.org/xy'); | |
$web = $xmlObj->xpath('/emp/website'); | |
var_dump($web); | |
/* | |
outputs: | |
array(1) { | |
[0]=> | |
object(SimpleXMLElement)#2 (2) { | |
["@attributes"]=> | |
array(1) { | |
["href"]=> | |
string(24) "http://www.xyz.com/peter" | |
} | |
[0]=> | |
string(16) "Peter's Homepage" | |
} | |
} | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment