@param \SimpleXMLElement $parent
@param                   $xml
@param bool              $before

@return bool
336552
protected function simplexmlImportXml(\SimpleXMLElement $parent, $xml, $before = false)
    {
        $xml = (string)$xml;
        if ($nodata = !strlen($xml) or $parent[0] == null) {
            return $nodata;
        }

        $node = dom_import_simplexml($parent);
        $fragment = $node->ownerDocument->createDocumentFragment();
        $fragment->appendXML($xml);

        if ($before) {
            return (bool)$node->parentNode->insertBefore($fragment, $node);
        }

        return (bool)$node->appendChild($fragment);
    }
1315490
private function parseXml($xml)
    {
        $priorSetting = libxml_use_internal_errors(true);
        try {
            libxml_clear_errors();
            $xmlPayload = new \SimpleXMLElement($xml);
            if ($error = libxml_get_last_error()) {
                throw new \RuntimeException($error->message);
            }
        } catch (\Exception $e) {
            throw new ParserException("Error parsing XML: {$e->getMessage()}", 0, $e);
        } finally {
            libxml_use_internal_errors($priorSetting);
        }

        return $xmlPayload;
    }
1072047
public function toXML(DOMElement $parent) : DOMElement
    {
        Assert::notEmpty($this->AttributeService);

        $e = parent::toXML($parent);

        foreach ($this->AttributeService as $ep) {
            $ep->toXML($e, 'md:AttributeService');
        }

        foreach ($this->AssertionIDRequestService as $ep) {
            $ep->toXML($e, 'md:AssertionIDRequestService');
        }

        Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->NameIDFormat);

        Utils::addStrings($e, Constants::NS_MD, 'md:AttributeProfile', false, $this->AttributeProfile);

        foreach ($this->Attribute as $a) {
            $a->toXML($e);
        }

        return $e;
    }
1146647
protected function arrayToXml($data, \SimpleXmlElement $element, $parent = null)
    {
        foreach ($data as $key => $value) {
            if (is_array($value) || $value instanceof \Traversable) {
                if (!is_numeric($key)) {
                    if (count($value) > 0 && isset($value[0])) {
                        $this->arrayToXml($value, $element, $key);
                    } else {
                        $subnode = $element->addChild($key);
                        $this->arrayToXml($value, $subnode, $key);
                    }
                } else {
                    $subnode = $element->addChild($parent);
                    $this->arrayToXml($value, $subnode, $parent);
                }
            } else {
                if (!is_numeric($key)) {
                    if (substr($key, 0, 1) === '@') {
                        $element->addAttribute(substr($key, 1), $value);
                    } elseif ($key === 'value' and count($data) === 1) {
                        $element[0] = $value;
                    } elseif (is_bool($value)) {
                        $element->addChild($key, intval($value));
                    } else {
                        $element->addChild($key, htmlspecialchars($value, ENT_QUOTES));
                    }
                } else {
                    $element->addChild($parent, htmlspecialchars($value, ENT_QUOTES));
                }
            }
        }
    }
851878
protected function _pushParent(&$parent)
    {
        $children    = &$this->_getElementChildren($parent);
        $pathSegment = $this->_getElementPathSegment(null, $parent);

        $this->_pushPathSegment($pathSegment);

        reset($children);
        array_unshift($this->parents, $children);
    }
1235748
protected function before(Context $context)
    {
        // set context forwarder
        $context->forwarder = $context->forwarder ?: [$this, 'forward'];

        return parent::before($context);
    }
111374
public static void insertBefore(Element newElement, Element before) {
        before.parentNode.insertBefore(newElement, before);
    }
677098
public static function add($parent = false)
    {
        $db = Database::connection();
        $treeNodeParentID = 0;
        $treeID = 0;
        $treeNodeDisplayOrder = 0;
        $inheritPermissionsFromTreeNodeID = 0;
        if (is_object($parent)) {
            $treeNodeParentID = $parent->getTreeNodeID();
            $treeID = $parent->getTreeID();
            $inheritPermissionsFromTreeNodeID = $parent->getTreeNodePermissionsNodeID();
            $treeNodeDisplayOrder = (int) $db->fetchColumn('select count(treeNodeDisplayOrder) from TreeNodes where treeNodeParentID = ?', [$treeNodeParentID]);
            $parent->updateDateModified();
        } else {
            $parent = null;
        }

        $treeNodeTypeHandle = uncamelcase(strrchr(get_called_class(), '\\'));

        $dateModified = Core::make('date')->toDB();
        $dateCreated = Core::make('date')->toDB();

        $type = TreeNodeType::getByHandle($treeNodeTypeHandle);
        $db->executeQuery(
            'insert into TreeNodes (treeNodeTypeID, treeNodeParentID, treeNodeDisplayOrder, inheritPermissionsFromTreeNodeID, dateModified, dateCreated, treeID) values (?, ?, ?, ?, ?, ?, ?)',
            [
                $type->getTreeNodeTypeID(),
                $treeNodeParentID,
                $treeNodeDisplayOrder,
                $inheritPermissionsFromTreeNodeID,
                $dateModified,
                $dateCreated,
                $treeID,
            ]
        );
        $id = $db->lastInsertId();
        $node = self::getByID($id);

        if (!$inheritPermissionsFromTreeNodeID) {
            $node->setTreeNodePermissionsToOverride();
        }

        if ($parent !== null && $parent->childNodesLoaded) {
            $parent->childNodes[] = $node;
        }

        return $node;
    }
324732
public function moveAsPrevSiblingOf(NodeInterface $beforeNode)
	{
		$pos = $beforeNode->getLeftValue();
		$level = $beforeNode->getLevel();
		$this->move($pos, $level);
		
		return $this;
	}
534178
public function setParent($parent)
    {
        if (empty($parent) || $this->getRefId() == $parent->getRefId() ||
            $parent->hasAncestor($this) || $this->hasReachedAncestorLimit()) {
            return false;
        }
        unset($this->parent);
        unset($parent->children);
        $this->trigger(static::$eventParentChanged);
        $parent->trigger(static::$eventChildAdded);
        return $this->{$this->parentAttribute} = $parent->getRefId();
    }
767000
public function wrap(string $before, string $after) : Testable
    {
        $this->htmlBefore = $before;
        $this->htmlAfter = $after;
        return $this;
    }
350952
public function createElement(Node $parent, $name)
    {
        if (array_key_exists($name, $this->elementMap)) {
            $class = $this->elementMap[$name];

            return new $class($parent);
        }

        return null;
    }
715197
private function buildXmlDir($parentXmlElement, $parentDirectory)
    {
        $xmlDir = $parentXmlElement->addChild('dir');
        $xmlDir->addAttribute('name', $parentDirectory['name']);

        foreach ($parentDirectory['directories'] as $directory) {
            $this->buildXmlDir($xmlDir, $directory);
        }
        foreach ($parentDirectory['files'] as $file) {
            $this->buildXmlFile($xmlDir, $file, $parentDirectory['real_path']);
        }

        return $this;
    }
882662
protected function parseXML($xml) {
        if (!$xml){
            return false;
        }
        $i = 0;
        foreach($xml->children() as $x){
            foreach($x->ShipToAddress->children() as $y => $z){
                $this->planList[$i]['ShipToAddress'][$y] = (string)$z;
                
            }
            $this->planList[$i]['ShipmentId'] = (string)$x->ShipmentId;
            $this->planList[$i]['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId;
            $this->planList[$i]['LabelPrepType'] = (string)$x->LabelPrepType;
            $j = 0;
            foreach($x->Items->children() as $y => $z){
                $this->planList[$i]['Items'][$j]['SellerSKU'] = (string)$z->SellerSKU;
                $this->planList[$i]['Items'][$j]['Quantity'] = (string)$z->Quantity;
                $this->planList[$i]['Items'][$j]['FulfillmentNetworkSKU'] = (string)$z->FulfillmentNetworkSKU;
                if (isset($z->PrepDetailsList)) {
                    foreach ($z->PrepDetailsList as $zz) {
                        $temp = array();
                        $temp['PrepInstruction'] = (string)$zz->PrepInstruction;
                        $temp['PrepOwner'] = (string)$zz->PrepOwner;
                        $this->planList[$i]['Items'][$j]['PrepDetailsList'][] = $temp;
                    }
                }
                $j++;
                
            }
            $i++;
        }
    }
402009
public function toXML(DOMElement $parent = null) : DOMElement
    {
        if ($parent === null) {
            $parent = DOMDocumentFactory::create();
            $doc = $parent;
        } else {
            $doc = $parent->ownerDocument;
        }
        $element = $doc->createElementNS(Constants::NS_SAML, $this->nodeName);
        $parent->appendChild($element);

        if ($this->NameQualifier !== null) {
            $element->setAttribute('NameQualifier', $this->NameQualifier);
        }

        if ($this->SPNameQualifier !== null) {
            $element->setAttribute('SPNameQualifier', $this->SPNameQualifier);
        }

        return $element;
    }
13813
@Override
    Object parent() {
        if (length() == 0) return Undefined.instance;

        XML candidateParent = null;

        for (int i = 0; i < length(); i++) {
            Object currParent = getXmlFromAnnotation(i).parent();
            if (!(currParent instanceof XML)) return Undefined.instance;
            XML xml = (XML)currParent;
            if (i == 0) {
                // Set the first for the rest to compare to.
                candidateParent = xml;
            } else {
                if (candidateParent.is(xml)) {
                    //    keep looking
                } else {
                    return Undefined.instance;
                }
            }
        }
        return candidateParent;
    }
1063064
final public function write($xml)
    {

        if($xml instanceof \SimpleXMLElement){
            $xml = $xml->asXML();
        } elseif($xml instanceof \DOMDocument){
            $xml = $xml->saveXML();
        }

        $this->log("SENT: ".$xml);

        return parent::write($xml);
    }