Safely get an attribute value.
@param \DOMNode $node
@param string $attr
@param mixed|null $default
@return null|string
429035
private function getAttr(\DOMNode $node, $attr, $default = null)
    {
        $attr = $node->attributes->getNamedItem($attr);
        return isset($attr) ? $attr->nodeValue : $default;
    }
164767
public function get($attribute = null, $default = null)
    {
        if (is_null($attribute)) {
            return $this->attributes;
        }

        if (array_key_exists($attribute, $this->attributes)) {
            return $this->attributes[$attribute];
        }

        return $default;
    }
1232785
function attribute( $attr )
    {
        switch ( $attr )
        {
            case "original_filename":
                return $this->OriginalFilename;
            case "mime_type":
                return $this->Type;
            case "mime_type_category":
                return $this->MimeCategory;
            case "mime_type_part":
                return $this->MimePart;
            case "filename":
                return $this->Filename;
            case "filesize":
                return $this->Size;
            case "is_temporary":
                return $this->IsTemporary;
            default:
            {
                eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ );
                return null;
            } break;
        }
    }
1300007
public function attr($attr)
    {
        $data = [];

        foreach ($this->_nodes as $node) {
            $data[] = $node->getAttribute($attr);
        }

        return $data;
    }
667100
protected String getElementAttribute(Element element, String attrName)
    {
        Attr attr = element.getAttributeNode(attrName);
        return attr != null ? attr.getValue() : null;
    }
344447
public function getAttribute($attribute, $defaultValue = null)
    {
        return array_get($this->cart->attributes, $attribute, $defaultValue);
    }
173413
protected function getOptionalNodeAttribute(\DOMNode $node, $name, $default = null)
    {
        $attribute = $node->attributes->getNamedItem($name);
        if ($attribute) {
            return $attribute->nodeValue;
        }

        return $default;
    }
934274
public function getContentsByAttr($attr, $attr_value) {
        $nodes = $this->_dom_x_path->query("//*[contains(@{$attr}, '{$attr_value}')]");
        
        $contents = [];
        
        foreach ($nodes as $node) {
            array_push($contents, $node->nodeValue);
        }
        
        return $contents;
    }
325718
public static String getAttributeString(Tag tag, String attrName, String defaultValue) {
	Literal lit = getAttributeLiteral(tag, attrName, null);
	if (lit == null) return defaultValue;
	return lit.getString();
    }
479935
private function getTagAttribute(StructureMetadata $metadata, $tag, $attribute, $default)
    {
        if (!$metadata->hasTag($tag)) {
            return $default;
        }

        $tag = $metadata->getTag($tag);
        if (!array_key_exists($attribute, $tag['attributes'])) {
            return $default;
        }

        return $tag['attributes'][$attribute];
    }
153865
public function getMetadataAttr(string $attr, $defaultValue = null, array $options = [])
    {
        return $this->getMetadata()->get($attr, $defaultValue, $options);
    }
161749
private function getAttributeValue($value, $attrKey = null)
    {
        if (is_bool($value)) {
            return $value ? 'true' : 'false';
        }

        return is_scalar($value) ? $value : null;
    }
1148780
protected function extendedAttr(DOMNode $node, DOMAttr $attr)
	{
		$handler = 'extendedAttr' . $attr->name;

		if (method_exists($this, $handler))
		{
			$this->$handler($node, $attr);
		}
		else
		{
            Eresus_Kernel::log(__METHOD__, LOG_WARNING, 'Unsupported EresusForm attribute "%s"', $attr->name);
		}

		$node->removeAttributeNode($attr);
	}
828828
protected static function DOMNodeValue(DOMNode $node, $associative = false, $attributes = false)
    {
        // Return the value immediately when we're dealing with a leaf
        // node without attributes or we simply don't want them included
        if (static::DOMNodeChildCount($node) == 0 && ($node->hasAttributes() === false || $attributes === false)) {
            return $node->nodeValue;
        }

        $children = array();

        if ($node->hasAttributes() && $attributes) {
            $children['@'] = static::DOMNodeAttributes($node);
        }

        foreach ($node->childNodes as $child) {
            // Skip text nodes containing whitespace
            if ($child instanceof DOMText && $child->isWhitespaceInElementContent()) {
                continue;
            }

            if (static::DOMNodeChildCount($child) > 0) {
                $value = static::DOMNodeValue($child, $associative);
            } else {
                $value = $child->nodeValue;
            }

            if ($associative) {
                $children[$child->nodeName][] = $value;
            } else {
                $children[] = $value;
            }
        }

        return $children;
    }
587221
public function getAttr($attr)
    {
        $attributeValue = $this->con->evaluateJavascript(sprintf('%s.getAttribute(%s)', $this->getAccessor(), json_encode($attr)));

        if ($attributeValue === false) {
            // see https://github.com/kriswallsmith/Buzz/pull/138 bug
            return '';
        }

        return $attributeValue;
    }
1054255
public function attr($name, $value = NULL) {
    if (($el = $this->getElement()) === NULL) return NULL;

    if ($el->hasAttribute($name)) {
      if (func_num_args() == 2) {
        $el->setAttribute($name, $value);
      }

      return $el->getAttribute($name);
    }

    return NULL;
  }
847434
private function get_attrs()
    {
        $this->attrs = new \stdClass;

        foreach($this->dom_element->attributes as $name => $node)
        {
            $this->attrs->{strtolower($name)} = $node->nodeValue;
        }
        return $this;
    }