Fix XPath parser

This commit is contained in:
Swappp 2009-01-26 23:49:30 +03:00 committed by Alexei Sorokin
parent d95381f8fb
commit a5346a47dc
1 changed files with 7 additions and 11 deletions

View File

@ -558,20 +558,16 @@ class XMLStream
*/
public function addXPathHandler(string $xpath, string $pointer, ?string $obj = null): void
{
if (preg_match_all("/\(?{[^\}]+}\)?(\/?)[^\/]+/", $xpath, $regs)) {
$ns_tags = $regs[0];
if (preg_match_all('/\/?(\{[^\}]+\})?[^\/]+/', $xpath, $regs)) {
$tag = $regs[0];
} else {
$ns_tags = [$xpath];
$tag = [$xpath];
}
$xpath_array = [];
foreach ($ns_tags as $ns_tag) {
list($l, $r) = explode("}", $ns_tag);
if ($r != null) {
$xpart = [substr($l, 1), $r];
} else {
$xpart = [null, $l];
}
$xpath_array[] = $xpart;
foreach ($tag as $t) {
$t = ltrim($t, '/');
preg_match('/(\{([^\}]+)\})?(.*)/', $t, $regs);
$xpath_array[] = [$regs[2], $regs[3]];
}
$this->xpathhandlers[] = [$xpath_array, $pointer, $obj];
}