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