protected function addNamespaces(\stdClass $target, \DOMElement $node, Xpath $xpath)
{
if ($node->namespaceURI != '' && $node->prefix === '') {
if (!isset($target->{'@xmlns'})) {
$target->{'@xmlns'} = new \stdClass();
}
$target->{'@xmlns'}->{'$'} = $node->namespaceURI;
}
foreach ($xpath->evaluate('namespace::*', $node) as $namespace) {
if ($namespace->localName === 'xml' || $namespace->localName === 'xmlns') {
continue;
}
if (!isset($target->{'@xmlns'})) {
$target->{'@xmlns'} = new \stdClass();
}
if ($namespace->nodeName !== 'xmlns') {
$target->{'@xmlns'}->{$namespace->localName} = $namespace->namespaceURI;
}
}
}