Build a DOM item.

@param string $name
@param string $value
@param string $namespaceURI
@param array  $attributes

@return DOMItem
@throws \InvalidArgumentException
326510
public function buildElement($name = '', $value = '', $namespaceURI = '', $attributes = [])
    {
        return new DOMItem($this->getDOMDocument(), $name, $value, $namespaceURI, $attributes);
    }
758313
public function appendAttr(string $name, string $value, string $separator = ';')
    {

        if (isset($this->attr[$name])) {
            $this->attr[$name] .= ($separator . $value);
        } else {
            $this->attr[$name] = $value;
        }

        return $this;
    }
1200734
public static function tag( $name, $attributes = array(), $value = null, $close = true, $selfClose = false )
    {
        //	Nah nah...
        if ( true !== $close )
        {
            $close = $selfClose = false;
        }

        $_html = static::openTag( $name, $attributes, $selfClose );

        if ( false !== $selfClose )
        {
            return $_html;
        }

        if ( null !== $value )
        {
            $_html .= trim( $value );
        }

        if ( $close )
        {
            $_html .= static::closeTag( $name );
        }

        return trim( $_html );
    }
1205145
public function addAttribute($name, $value = null, $namespace = null)
    {
        if (isset($value)) {
            parent::addAttribute($name, $value, $namespace);
        }
    }
883564
final protected function setAttribute($name, $value)
    {
        if ($value !== null && $this->hasAttributeValueFactory($name)) {
            $this->internalCache[$name] = $this->createAttributeValue($name, $value);

            if ($this->internalCache[$name] instanceof JsonSerializable) {
                $value = $this->internalCache[$name]->jsonSerialize();
            } elseif (is_array($this->internalCache[$name])) {
                $value = array_map(
                    function ($value) {
                        if ($value instanceof JsonSerializable) {
                            $value = $value->jsonSerialize();
                        }

                        return $value;
                    },
                    $this->internalCache[$name]
                );
            } else {
                $value = $this->internalCache[$name];
            }
        }

        $this->data[$name] = $value;

        return $this;
    }
765350
public function addAttribute($name, $value = null, $namespace = null)
    {
        parent::addAttribute($name, ($value !== null ? str_replace('&', '&amp;', $value) : null), $namespace);
    }
637020
public function setAttr(string $name, string $value)
    {
        $this->attr[$name] = $value;

        return $this;
    }
320437
public function url($name, $value = null, array $attributes = array(), array $extra = array())
    {
        return $this->build('url', $name, $value, $attributes, $extra);
    }
1340091
public function attr($name, $value = null){
        if(is_null($value)){
            return $this->getAttributeValue($name);
        }else{
            return $this->setAttribute($name, $value);
        }
    }
381358
public function setAttribute($name, $value){

        $returnValue = false;

        if(is_null($value)){
            return $returnValue;
        }

        if(isset($this->attributes[$name])){

            $datatypeClass = $this->attributes[$name]->getType();
            // check if the attribute needs an element level validation
            if(is_subclass_of($datatypeClass, 'oat\\taoQtiItem\\model\\qti\\datatype\\Identifier')){

                if($value instanceof IdentifiedElement){
                    if($this->validateAttribute($name, $value)){
                        $this->attributes[$name]->setValue($value);
                        $returnValue = true;
                    }else{
                        $vr = print_r($value, true);
                        common_Logger::w($vr);
                        throw new InvalidArgumentException('Invalid identifier attribute value');
                    }
                }elseif(is_string($value)){
                    // try converting to string identifier and search the identified object:
                    $identifier = (string) $value;
                    $elt = $this->getIdentifiedElement($identifier, $datatypeClass::getAllowedClasses());
                    if(!is_null($elt)){
                        // ok, found among allowed classes
                        $this->attributes[$name]->setValue($elt);
                        $returnValue = true;
                    }else{
                        throw new QtiModelException('No QTI element with the identifier has been found: '.$identifier);
                    }
                }
            }else{
                $this->attributes[$name]->setValue($value);
                $returnValue = true;
            }
        }else{
            $this->attributes[$name] = new Generic($value);
            $returnValue = true;
        }

        return $returnValue;
    }
979182
public function withAttribute($name, $value){
        if(!is_string($name)){
            throw new \InvalidArgumentException(
                "First argument must be of the type string, " . gettype($name) . " given."
            );
        }

        if(
            array_key_exists($name, $this->attributes)
            && $this->attributes[$name] === $value
        ){
            return $this;
        }

        $clone                      = clone $this;
        $clone->attributes[$name]   = $value;

        return $clone;
    }
891043
public function setAttribute($name, $value = null)
    {
        $name = strtolower($name);
        if (is_null($value)) {
            $value = $name;
        }
        if (in_array($name, $this->watchedAttributes)) {
            $this->onAttributeChange($name, $value);
        } else {
            $this->attributes[$name] = (string)$value;
        }
        return $this;
    }
473537
final public function withAttribute($name, $value = null, bool $inAllElements = false): self
    {
        // insert or update one or more attributes into all elements
        if (is_array($this->data) && $inAllElements === true) {
            foreach ($this->data as $dataKey => $element) {
                if (is_array($name)) {
                    $element = $this->addingAttribute($element, $name, $dataKey);
                    continue;
                }
                if (!is_array($name) && is_callable($value)) {
                    $element->$name = $value($this->rawData[$dataKey]);
                    continue;
                }
                $element->$name = $value;
            }

            return $this;
        } else {
            if ($inAllElements === true) {
                throw new \Exception("The results is not an array");
            }
        }

        if (is_array($name)) {
            foreach ($name as $attributeKey => $attributeValue) {
                if (is_array($this->data)) {
                    $this->data[$attributeKey] = is_callable($attributeValue) ? $attributeValue($this->rawData) : $attributeValue;
                } else {
                    $this->data->$attributeKey = is_callable($attributeValue) ? $attributeValue($this->rawData) : $attributeValue;
                }
            }
            return $this;
        }

        if (is_array($this->data)) {
            $this->data[$name] = is_callable($value) ? $value($this->rawData) : $value;
        } else {
            $this->data->$name = is_callable($value) ? $value($this->rawData) : $value;
        }

        return $this;
    }
528967
public function appendAttr($name, $value, $separator = '')
    {
        if ($this->existsAttr($name)) {

            if ($name == 'class') {
                $separator = ' ';
            }

            $this->attrs[$name] .= $separator . trim($value);

        } else {
            $this->attrs[trim($name)] = trim($value);
        }

        return $this;
    }
642523
public static function url($name, $value, array $attributes = array())
    {
        $node = new Node\Url();

        if (!is_null($name)) {
            $attributes['name'] = $name;
        }

        if (!is_null($value)) {
            $attributes['value'] = $value;
        }

        return $node->render($attributes);
    }
87665
public static function addAttribute(\DOMNode $rootNode, $name, $value)
    {
        XmlUtil::checkIfPrefixWasDefined($rootNode, $name);

        $owner = XmlUtil::getOwnerDocument($rootNode);
        $attrNode = $owner->createAttribute($name);
        $attrNode->value = $value;
        $rootNode->setAttributeNode($attrNode);
        return $rootNode;
    }
876867
public static function input(
        string $name, 
        string $type = "text", 
        string $value = null, 
        array $attributes = []
    ) : string 
    {
        $preAttributesInput = [
            "name" => $name,
            "type" => $type,
        ];
        if (!is_null($value)) {
            $preAttributesInput["value"] = $value;
        }
        $attributesInput = array_merge($preAttributesInput, $attributes);
        return self::tag("input", "", $attributesInput);
    }