You have got an invalid xpath query which needs to be fixed because an invalid xpath query will always result in an error. You can not use the outcome of it to get nodes out of it.
Unfortunately the xpath query is invalid because the XML is invalid. So you can not use the xpath query (or further test it / continue to write it) without fixing the XML first.
From the XML you've provided in your question it's apparently missing the namespace declaration of the w-prefix.
You need to enable error reporting to the highest level (E_ALL
), display of errors in your development environment and generally the error logging. You then can follow the error log:
Warning: DOMDocument::loadXML(): Namespace prefix w on document is not defined in Entity, line: 1 in /tmp/execpad-1d8a88cab4fd/source-1d8a88cab4fd on line 15
Warning: DOMDocument::loadXML(): Namespace prefix w on body is not defined in Entity, line: 2 in /tmp/execpad-1d8a88cab4fd/source-1d8a88cab4fd on line 15
Warning: DOMDocument::loadXML(): Namespace prefix w on p is not defined in Entity, line: 3 in /tmp/execpad-1d8a88cab4fd/source-1d8a88cab4fd on line 15
Warning: DOMDocument::loadXML(): Namespace prefix w on r is not defined in Entity, line: 4 in /tmp/execpad-1d8a88cab4fd/source-1d8a88cab4fd on line 15
Warning: DOMDocument::loadXML(): Namespace prefix w on t is not defined in Entity, line: 5 in /tmp/execpad-1d8a88cab4fd/source-1d8a88cab4fd on line 15
Warning: DOMXPath::query(): Undefined namespace prefix in /tmp/execpad-1d8a88cab4fd/source-1d8a88cab4fd on line 17
Warning: DOMXPath::query(): Invalid expression in /tmp/execpad-1d8a88cab4fd/source-1d8a88cab4fd on line 17
Fatal error: Call to a member function item() on a non-object in /tmp/execpad-1d8a88cab4fd/source-1d8a88cab4fd on line 18
As these show, there are many problems with the XML which in the end renders the xpath query invalid and finally bring your whole script to halt.