|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42325 xmlns parsing issues
Submitted: 2007-08-17 04:08 UTC Modified: 2007-08-18 09:48 UTC
From: cpriest at warpmail dot net Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.4RC2 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
40 - 22 = ?
Subscribe to this entry?

 [2007-08-17 04:08 UTC] cpriest at warpmail dot net
SimpleXML is having some difficulty in parsing XML which contains a default xmlns entry.

Reproduce code:
	header('Content-Type: text/plain');
	$ResponseBody = '<?xml version="1.0" encoding="UTF-8"?>
<result xmlns="" xmlns:xsd="" xmlns:xsi="">Test</result>';
	$objXML = new SimpleXMLElement($ResponseBody);
	$tMatches = $objXML->xpath('/result');

Expected result:
Expect print_r() to print "Test"

Actual result:
$tMatches is an empty array()

If you change the xmlns="" to xmlns:zzz="" (add a namespace sub-string), it works fine.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-17 07:01 UTC]
You have to register default namespaces with

 [2007-08-17 14:35 UTC] cpriest at warpmail dot net
I'm not sure I understand why I would have to call registerXPathNamespace() to use a default namespace?  I thought one of the reasons to use SimpleXML was to parse XML documents.

If I make the one default namespace (xmlns="") a non-default such as xmlns:test=, then it properly queries the /result value.

To do what you're suggestion I would have to parse the XML document myself looking for the namespace I would want to query against.

The code below also works if you simply remove the xmlns="" attribute.  Are you sure that I'm supposed to be using registerXPathNamespace()
 [2007-08-17 14:45 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

 [2007-08-17 16:30 UTC] cpriest at warpmail dot net
Why is this bogus?  Does anyone actually even read these reports?
 [2007-08-17 19:52 UTC]
This is not a help desk. Thats how XPath and default namespaces work.
 [2007-08-18 04:42 UTC] cpriest at warpmail dot net
Okay, this is a little frustrating here, I don't have infinite amount of time to get a bug report through to you.

I am trying to use the DEFAULT NAMESPACE.  I couldn't use registerXPathNamespace() if I wanted to, there is no prefix or namespace to declare to use it with.

 [2007-08-18 09:48 UTC]
DO NOT RE-OPEN. This is not a bug.
A simple online search would give you more than enough information on this (since you are ignoring Chregu's advice). This has nothing to do with SimpleXML or PHP. It is simply how you need to work with XPath and default namespaces (yes I said DEFAULT NAMESPACES) within any language.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Sep 25 20:01:25 2023 UTC