Page MenuHomePhabricator

Underlying SimpleXMLElement::xpath fails for docs with default namespace xmlns
Closed, ResolvedPublicBUG REPORT


Steps to Reproduce:

Parse any xml doc with xmlns default namespace, e. g.

{{#get_web_data:url=|format=xml|use xpath|data=res=/Record/RecordType}}
res: {{#for_external_table:{{{res}}} }}

Actual Results:

Results are always empty, example:


Expected Results:

Non-empty results, example:

res: CID

As a workaround, xmlns could be replaced with ns in the xml string in EDParserXMLwithXPath.php (see patch):

$text = str_replace('xmlns=', 'ns=', $text);

(see also comments on

Event Timeline

alex-mashin triaged this task as Unbreak Now! priority.
alex-mashin added a subscriber: Yaron_Koren.

Change 675350 had a related patch set uploaded (by Alex Mashin; author: mashin):
[mediawiki/extensions/ExternalData@master] Ignore xmlns in XML to be indexed with XPath

On stackoverflow there are some suggestions for a more robust solution for this limitation of XPath1,
e. g. using regex or iterate over all nodes an check for default namespace declarations.

Change 675350 merged by jenkins-bot:

[mediawiki/extensions/ExternalData@master] Add the parameter 'default xmlns prefix' when querying XML with XPath

Parameter 'default xmlns prefix' is added to be used as default prefix for xmlns when no prefix is provided in the XML.

It is wiki user's responsibility to use this namespace prefix in his XPath queries.

A working example of 'default xmlns prefix':

 | format=xml
 | use xpath
 | data=res=/ns:Record/ns:RecordType
 | default xmlns prefix=ns
}}res: {{#for_external_table:{{{res}}} }}