Actions
Bug #6526
openPHP API xdmNode->axisNodes(3) returns the XdmNode itself instead of its children
Start date:
2024-09-10
Due date:
% Done:
0%
Estimated time:
Applies to branch:
12
Fix Committed on Branch:
Fixed in Maintenance Release:
Found in version:
12.5
Fixed in version:
SaxonC Languages:
SaxonC Platforms:
All
SaxonC Architecture:
Description
Trying to use axisNodes(3) with PHP to find the child nodes of an XdmNode, I get some strange results, I don't get an XdmValue containing a sequence of nodes but I get an XdmNode which seems to be the same as the method is called on.
Sample code is e.g.
<?php
$xml = <<<XML
<root att1="value 1" att2="value 2">
<foo>bar</foo>
</root>
<!-- comment 1 -->
XML;
$saxonProc = new Saxon\SaxonProcessor();
$xdmNode = $saxonProc->parseXmlFromString($xml);
echo $xdmNode->getChildCount() . "\n";
$childrenAxis = $xdmNode->axisNodes(3);
var_dump($childrenAxis);
echo get_class($childrenAxis) . "\n";
echo $childrenAxis . "\n";
echo $childrenAxis->getNodeKind() . "\n";
$xdmNode = $xdmNode->getChildNode(0);
echo $xdmNode->getChildCount() . "\n";
$childrenAxis = $xdmNode->axisNodes(3);
var_dump($childrenAxis);
echo get_class($childrenAxis) . "\n";
echo $childrenAxis . "\n";
echo $childrenAxis->getNodeKind() . "\n";
unset($childrenAxis);
unset($xdmNode);
unset($saxon_proc);
?>
and output for me (with SaxonC HE 12.5 under Ubuntu 24 WSL with PHP 8.3) is
2
object(Saxon\XdmNode)#3 (0) {
}
Saxon\XdmNode
<root att1="value 1" att2="value 2">
<foo>bar</foo>
</root>
<!-- comment 1 -->
0
3
object(Saxon\XdmNode)#2 (0) {
}
Saxon\XdmNode
<foo>bar</foo>
0
Updated by Martin Honnen 3 months ago
It seems axisNodes
from PHP is broken for other axis as well, today I have the preceding sibling axis with e.g.
<?php
$xml = <<<XML
<!-- comment 1 -->
<?pi test?>
<root att1="value 1" att2="value 2">
<foo>bar</foo>
<foo>baz</foo>
</root>
<!-- comment 2 -->
XML;
$saxonProc = new Saxon\SaxonProcessor();
$xdmNode = $saxonProc->parseXmlFromString($xml);
echo $xdmNode->getChildCount() . "\n";
$xpathProc = $saxonProc->newXPathProcessor();
$xpathProc->setContextItem($xdmNode);
$xdmItem = $xpathProc->evaluateSingle('/comment()[last()]');
echo "$xdmItem\n";
echo $xdmItem->isNode() . "\n";
$xdmNode2 = $xdmItem->getNodeValue();
echo "$xdmNode2\n";
$siblingNodes = $xdmNode2->axisNodes(11);
var_dump($siblingNodes);
echo get_class($siblingNodes) . "\n";
echo "$siblingNodes\n";
unset($siblingNodes);
unset($xdmNode);
unset($xdmNode2);
unset($saxon_proc);
?>
but the result is an error
4
<!-- comment 2 -->
1
<!-- comment 2 -->
NULL
PHP Fatal error: Uncaught TypeError: get_class(): Argument #1 ($object) must be of type object, null given in /home/mh/axisNodesTest2.php:35
Stack trace:
#0 {main}
thrown in /home/mh/axisNodesTest2.php on line 35
so somehow it appears in PHP $xdmNode2->axisNodes(11)
returns NULL while the node has three preceding sibling nodes (when using the Python API).
Updated by O'Neil Delpratt 4 days ago
- Assignee changed from O'Neil Delpratt to Matt Patterson
Please register to edit this issue
Actions