|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-03-26 08:09 UTC] rrichards@php.net
[2004-06-04 11:59 UTC] davey@php.net
[2004-06-07 09:45 UTC] chregu@php.net
[2004-08-27 10:25 UTC] chregu@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sun Feb 08 01:00:01 2026 UTC |
Description: ------------ Hi, this example works with SimpleXML xpath: $string = <<<XML <?xml version="1.0" encoding ="UTF-8" ?> <a xmlns:ns="urn:1"> <b> <c>text</c> <c>stuff</c> </b> <d> <c>code</c> </d> </a> XML; $xml = simplexml_load_string($string); $res = $xml->xpath('//a'); // returns array(1) But if we don't use a namespace prefix (default namespace), xpath, returns an empty array, array(0), for any xpath search: $string = <<<XML <?xml version="1.0" encoding ="UTF-8" ?> <a xmlns="urn:1"> <b> <c>text</c> <c>stuff</c> </b> <d> <c>code</c> </d> </a> XML; $xml = simplexml_load_string($string); $res = $xml->xpath('//a'); // returns array(0) This is a simple example, I found the problem with a bigger XML file (a WSDL file). This WSDL has 5 namespaces defined, and no problem at all with SimpleXML, as long as you don't define a default namespace... Thanks for your attention