Utility method to add new elements to an xml node if their value is not empty.

@param \DOMDocument $dom xml document
@param \DOMElement $node where to add the new element
@param string $name of the new element
@param string $value of the new element
197979
private function addNewNotEmptyXmlElement(DOMDocument $dom, DOMElement $node, $name, $value)
    {
        if (!empty($value)) {
            $this->addNewXmlElement($dom, $node, $name, $value);
        }
    }
66678
static protected function _set_body_link(\DOMElement $node, $value)
    {
        $a_list = $node->getElementsByTagName("a");
        $value = self::_get_valid_color($value);

        foreach ($a_list as $a) {
            self::append_style($a, "; color: $value;");
        }

        return null;
    }
1320875
static public function changeElementName(DOMElement $element, $name)
    {
        $newElement = $element->ownerDocument->createElement($name);

        foreach ($element->childNodes as $child) {
            $child = $element->ownerDocument->importNode($child, true);
            $newElement->appendChild($child);
        }

        foreach ($element->attributes as $attrName => $attrNode) {
            if ($attrNode->namespaceURI === null) {
                $newElement->setAttribute($attrName, $attrNode->value);
            } else {
                $newElement->setAttributeNS($attrNode->namespaceURI, $attrNode->prefix . ':' . $attrName, $attrNode->value);
            }

        }

        $newElement->ownerDocument->replaceChild($newElement, $element);

        return $newElement;
    }
265453
protected function addDescription(\DOMElement $node, DescriptorAbstract $element)
    {
        $node->appendChild(new \DOMElement('long-description'))
            ->appendChild(new \DOMText($element->getDescription()));
    }
733137
public function setElementValue($element, $value)
    {
        $node = $this->dom->createTextNode($value);
        $element->appendChild($node);
    }
1258650
private function createNumberNode(\DOMDocument $document, $value, string $name = null): \DOMNode
    {
        $node = $document->createElement('json:number', (string) $value);

        if (null !== $name) {
            $node->setAttribute('name', $name);
        }

        return $node;
    }
780596
protected function addXmlElement(\DOMNode $parentNode, string $nodeName, string $namespace): \DOMNode
    {
        $node = $parentNode->appendChild(
            ($parentNode->ownerDocument ?? $parentNode)->createElementNS($namespace, $nodeName)
        );

        return $node;
    }
880499
protected function hydrateNameValuePair($name, $value, DOMDocument $xml)
    {
        $nvp = $xml->createElement('hps:NameValuePair');
        $nvp->appendChild($xml->createElement('hps:Name', $name));
        $nvp->appendChild($xml->createElement('hps:Value', HpsInputValidation::cleanAscii($value)));
        return $nvp;
    }
479836
protected function addSequentialNode(DOMElement $element, $value): void
    {
        if (empty($element->nodeValue)) {
            $element->nodeValue = \htmlspecialchars($value);
            return;
        }

        $child = $this->element($element->nodeName);
        $child->nodeValue = \htmlspecialchars($value);
        $element->parentNode->appendChild($child);
    }
1324625
private function createText(\DOMDocument $dom, \DOMNode $node, $value)
    {
        $text = $dom->createTextNode($value);
        $node->appendChild($text);
    }
1256152
public function setAttribute($name, $value)
    {
        foreach ($this as $node) {
            if ($node instanceof \DOMElement) {
                /** @var \DOMElement $node */
                $node->setAttribute($name, $value);
            }
        }
        return $this;
    }
69244
public function add(\DOMElement $node) {
		$name = $node->getAttribute('name');
		if($this->has($name))
			$this->get($name)->addChoice($node);
		else
			$this->set($name, new Field($node));
	}
805819
private function convertElement(DOMElement $element, $value)
    {
        $sequential = $this->isArrayAllKeySequential($value);

        if (! is_array($value)) {
            $value = htmlspecialchars($value);

            $value = $this->removeControlCharacters($value);

            $element->nodeValue = $value;

            return;
        }

        foreach ($value as $key => $data) {
            if (! $sequential) {
                if (($key === '_attributes') || ($key === '@attributes')) {
                    $this->addAttributes($element, $data);
                } elseif ((($key === '_value') || ($key === '@value')) && is_string($data)) {
                    $element->nodeValue = htmlspecialchars($data);
                } elseif ((($key === '_cdata') || ($key === '@cdata')) && is_string($data)) {
                    $element->appendChild($this->document->createCDATASection($data));
                } elseif ((($key === '_mixed') || ($key === '@mixed')) && is_string($data)) {
                    $fragment = $this->document->createDocumentFragment();
                    $fragment->appendXML($data);
                    $element->appendChild($fragment);
                } else {
                    $this->addNode($element, $key, $data);
                }
            } elseif (is_array($data)) {
                $this->addCollectionNode($element, $data);
            } else {
                $this->addSequentialNode($element, $data);
            }
        }
    }
767094
private function appendTextNode(\DOMDocument $dom, $node, $value)
    {
        if (in_array(strtolower($value), ['true', 'false']) || is_numeric($value)) {
            return $this->createTextNodeWithTypeAttribute($dom, $node, $value, 'string');
        }
        if (preg_match('/(<|>|&)/i', $value)) {
            return $this->createCDATASection($dom, $node, $value);
        }

        return $this->createText($dom, $node, $value);
    }
613059
protected function addCollectionNode(DOMElement $element, $value)
    {
        if ($element->childNodes->length === 0 && $element->attributes->length === 0) {
            $this->convertElement($element, $value);

            return;
        }

        $child = $this->document->createElement($element->tagName);
        $element->parentNode->appendChild($child);
        $this->convertElement($child, $value);
    }
586064
private function fillElement (DOMDocument $doc, DOMElement $parent, array $filler)
    {
        foreach ($filler as $name => $value) {
            if ($value instanceof DOMElement) {
                $element = $value;
            } else {
                $element = $doc->createElement($name);
                
                if (is_array($value)) {
                    $this->fillElement($doc, $element, $value);
                } else {
                    $element->appendChild(new DOMCdataSection($value));
                }
            }
            
            $parent->appendChild($element);
        }
    }
755515
public function checkWithValue($name, $value)
    {
        /** @var \Behat\Mink\Element\NodeElement $nodeElement */
        $nodeElement = $this->getSession()->getPage()->find(
            'xpath',
            sprintf(
                '//input[@type="checkbox" and @name="%s" and @value="%s"]',
                $name,
                $value
            )
        );

        if (null === $nodeElement) {
            // Yikes! It aint where we want it
            throw new ExpectationException(
                sprintf(
                    'A checkbox with the value "%s" is not in the page.',
                    $value
                ),
                $this->getSession()->getDriver()
            );
        }

        // Make the magic happen
        $nodeElement->check();
    }