Get a child node, create it when it does not exist.

@param SimpleXMLElement $element
@param string           $name
@param array            $attributes

@return SimpleXMLElement
160224
public function getChild(
        SimpleXMLElement $element,
        $name,
        array $attributes = []
    ) {
        $xpath = $name . $this->getAttributesXpath($attributes);

        $result = $element->xpath($xpath);
        if (empty($result)) {
            $node = $element->addChild($name);
            $this->setAttributes($node, $attributes);
        } else {
            $node = reset($result);
        }

        return $node;
    }
931175
public static function create($name = 'null') {
    $is_upper = FormatterFactory::getDefaultFormatter()->getConfig('boolean_null_upper');
    $node = new NullNode();
    $node->addChild(NameNode::create($is_upper ? 'NULL' : 'null'), 'constantName');
    return $node;
  }
438518
public static String getAttributeValue(final Element element, final String name) {
        final Node node = element.getAttributes().getNamedItem(name);
        if (node != null) {
            return node.getNodeValue();
        }

        return null;
    }
179264
public function get($name)
    {
        if (array_key_exists($name, $this->elements)) {
            return $this->resolveXRef($name);
        }

        return new ElementMissing(null, null);
    }
579455
public function create($name, $attrs = NULL)
	{
		$this->insert(NULL, $child = static::el($name, $attrs));

		return $child;
	}
577828
public static function tag($name, $content = NULL, Array $attributes = NULL) {
    return \Psc\UI\HTML::tag($name, $content, $attributes);
  }
687664
public function getAttribute($xpath, $name) {
    $elements = $this->findElement($xpath, 1);
    return $this->browser->attribute($elements["page_id"], $elements["ids"][0], $name);
  }
597373
public function asXML($storage, string $name = null, array $attributes = []): string
    {
        $storage = $this->fragments($storage);
        $element = $this->element($name ?? $this->options()->getRootName());

        $this->addAttributes($element, $attributes);
        $this->document()->appendChild($element);
        $this->convert($element, $this->_convertStorage($storage));
        $xml = $this->document()->saveXML();

        $this->document = null;

        return $xml;
    }
271561
protected function getFormGroupWithoutLabel($name, $element)
    {
        $options = $this->getFormGroupOptions($name);

        return $this->toHtmlString('<div' . $this->html->attributes($options) . '>' . $element . '</div>');
    }
1351267
public function addElement($element, $title = null, $name = null, $attrs = null) {
		if (! $element instanceof Element &&
			! $element instanceof Divider) {
			
			if ($element === self::DIVIDER) {
				$element = new Divider(null, $attrs);
			} else {
				if ($title === null) {
					$title = $element;
				}
				
				$element = new Element($element, $title, $attrs);
			}
		}
		
		if ($name === null && $title !== null) {
			$name = $title;
		}
		
		return parent::addElement($element, $name);
	}
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;
    }
699197
public function iterateArray($name, $data)
    {
        if (\Genesis\Utils\Common::isValidXMLName($name)) {
            $this->context->startElement($name);
        }

        foreach ($data as $key => $value) {
            if (is_null($value)) {
                continue;
            }

            // Note: XMLWriter discards Attribute writes if they are written
            // after an Element, so make sure the attributes are at the top
            if ($key === '@attributes') {
                $this->writeAttribute($value);
                continue;
            }

            if ($key === '@cdata') {
                $this->writeCData($value);
                continue;
            }

            if ($key === '@value') {
                $this->writeText($value);
                continue;
            }

            $this->writeElement($key, $value);
        }

        if (\Genesis\Utils\Common::isValidXMLName($name)) {
            $this->context->endElement();
        }
    }
1230086
public function createChildOf(array $attributes, Node $parent)
    {
        // Get new position
        $position = $this->getLastChildPosition($parent);
        $attributes[$this->getPositionName()] = $position;

        $model = $this->performCreateChildOf($attributes, $parent);

        return $model;
    }
786716
protected function createElement($name)
    {
        if (isset($this->elements[$name])) {
            return $this->factory->createInlineElement($this->elements[$name]);
        }

        return $this->factory->createElement($name);
    }
350952
public function createElement(Node $parent, $name)
    {
        if (array_key_exists($name, $this->elementMap)) {
            $class = $this->elementMap[$name];

            return new $class($parent);
        }

        return null;
    }
423762
public function getElementsByName($name) {

		if(isset($this->elements[$name])) {
			return $this->elements[$name];
		}
		
		throw new \InvalidArgumentException(sprintf("Unknown form element '%s'", $name));

	}
373114
protected static function getBitfield(DOMElement $element, $name)
	{
		$props    = self::getProperties($element);
		$bitfield = self::toBin($props[$name]);

		// For each bit set to 1, test whether there is an XPath condition to it and whether it is
		// fulfilled. If not, turn the bit to 0
		foreach (array_keys(array_filter(str_split($bitfield, 1))) as $bitNumber)
		{
			$conditionName = $name . $bitNumber;
			if (isset($props[$conditionName]) && !self::evaluate($props[$conditionName], $element))
			{
				$bitfield[$bitNumber] = '0';
			}
		}

		return self::toRaw($bitfield);
	}