Last active
December 17, 2015 13:49
-
-
Save crilleengvall/5620201 to your computer and use it in GitHub Desktop.
Default namespaced xml and xpath
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
<?xml version="1.0"?> | |
<bookstore xmlns="urn:xmlns:25hoursaday-com:bookstore"> | |
<book> | |
<title>Lord of the Rings</title> | |
<author>J.R.R. Tolkien</author> | |
</book> | |
</bookstore> |
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
<?xml version="1.0"?> | |
<bk:bookstore xmlns:bk="urn:xmlns:25hoursaday-com:bookstore"> | |
<bk:book> | |
<bk:title>Lord of the Rings</bk:title> | |
<bk:author>J.R.R. Tolkien</bk:author> | |
</bk:book> | |
</bk:bookstore> |
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 | |
$xml = simplexml_load_file('namespaced.xml'); | |
$result = $xml->xpath('/bk:bookstore/bk:book/bk:title'); | |
echo $result[0]; | |
echo "<br />"; | |
$xml = simplexml_load_file('default-namespaced.xml'); | |
$result_from_default_namespace = $xml->xpath("/*[local-name()='bookstore']/*[local-name()='book']/*[local-name()='title']"); | |
echo $result_from_default_namespace[0]; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment