FluentDOM\Serializer\Json\BadgerFish::addNamespaces PHP Method

addNamespaces() protected method

protected addNamespaces ( stdClass $target, DOMElement $node, Xpath $xpath )
$target stdClass
$node DOMElement
$xpath FluentDOM\Xpath
    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;
            }
        }
    }