FluentDOM\Serializer\Json::getNamespaces PHP Method

getNamespaces() protected method

If compares the namespaces of the current node with the ones from the parent node. Only definitions that are different are returned.
protected getNamespaces ( DOMElement $node ) : array
$node DOMElement
return array
    protected function getNamespaces(\DOMElement $node)
    {
        $result = $this->getAllNamespaces($node);
        $inherited = [];
        if ($node->parentNode instanceof \DOMElement) {
            $inherited = $this->getAllNamespaces($node->parentNode);
        }
        return array_diff_assoc($result, $inherited);
    }

Usage Example

Example #1
0
 protected function getNamespaces(\DOMElement $node)
 {
     $result = [];
     foreach (parent::getNamespaces($node) as $prefix => $uri) {
         $attribute = new \stdClass();
         $attribute->{'#name'} = '@' . $prefix;
         $attribute->{'#text'} = $uri;
         $attribute->{'#children'} = [];
         $result[] = $attribute;
     }
     return $result;
 }