/**
* @throws \InvalidArgumentException
*/
private function discoverNamespace(\DOMXPath
$domxpath, string
$prefix): ?string
{ if (\
array_key_exists($prefix,
$this->namespaces
)) { return $this->namespaces
[$prefix];
} if ($this->cachedNamespaces->
offsetExists($prefix)) { return $this->cachedNamespaces
[$prefix];
} // ask for one namespace, otherwise we'd get a collection with an item for each node
$namespaces =
$domxpath->
query(sprintf('(//namespace::*[name()="%s"])[last()]',
$this->defaultNamespacePrefix ===
$prefix ? '' :
$prefix));
return $this->cachedNamespaces
[$prefix] =
($node =
$namespaces->
item(0
)) ?
$node->nodeValue : null;
} private function findNamespacePrefixes(string
$xpath): array
{