@param \HpsDirectMarketData $data
@param \DOMDocument         $xml

@return \DOMElement
322482
public function _hydrateDirectMarketData(HpsDirectMarketData $data, DOMDocument $xml)
    {
        $directMktDataElement = $xml->createElement('hps:DirectMktData');
        $directMktDataElement->appendChild($xml->createElement('hps:DirectMktInvoiceNbr', $data->invoiceNumber));
        $directMktDataElement->appendChild($xml->createElement('hps:DirectMktShipMonth', $data->shipMonth));
        $directMktDataElement->appendChild($xml->createElement('hps:DirectMktShipDay', $data->shipDay));

        return $directMktDataElement;
    }
1242447
public function _hydrateTokenData($token, DOMDocument $xml, $cardPresent = false, $readerPresent = false)
    {
        if (!$token instanceof HpsTokenData) {
            $tokenValue = $token;
            $token = new HpsTokenData();
            $token->tokenValue = $tokenValue;
        }

        $tokenData = $xml->createElement('hps:TokenData');
        $tokenData->appendChild($xml->createElement('hps:TokenValue', $token->tokenValue));

        if (isset($token->expMonth)) {
            $tokenData->appendChild($xml->createElement('hps:ExpMonth', $token->expMonth));
        }

        if (isset($token->expYear)) {
            $tokenData->appendChild($xml->createElement('hps:ExpYear', $token->expYear));
        }

        if (isset($token->cvv)) {
            $tokenData->appendChild($xml->createElement('hps:CVV2', $token->cvv));
        }

        $tokenData->appendChild($xml->createElement('hps:CardPresent', ($cardPresent ? 'Y' : 'N')));
        $tokenData->appendChild($xml->createElement('hps:ReaderPresent', ($readerPresent ? 'Y' : 'N')));
        return $tokenData;
    }
1061440
public function loadXML($xml_data)
    {
        $this->xml_data = $xml_data;
        $this->xml = new \sasco\LibreDTE\XML();
        if (!$this->xml->loadXML($this->xml_data)) {
            return false;
        }
        $this->toArray();
        return $this->xml;
    }
1070869
public function xml($data)
    {
        if ($data instanceof SimpleXMLElement) {
            $data = $data->saveXML();
        }
        $dom = new DOMDocument();
        $dom->loadXml($data);
        $dom->formatOutput = true;
        return $dom->saveXML();
    }
935926
public static function fromArray( $data, $rootName = null, $nodeName = null, $addHeader = true )
    {
        $_xml = true === $addHeader ? '<?xml version="1.0" encoding="UTF-8" ?>' : null;

        if ( null !== $rootName )
        {
            $_xml .= Markup::openTag( $rootName );
        }

        $_string = null;

        if ( $data instanceof \Traversable )
        {
            foreach ( $data as $_key => $_value )
            {
                if ( is_numeric( $_key ) )
                {
                    $_key = $nodeName ?: 'node';
                }

                $_string .= Markup::tag( $_key, array(), static::fromArray( $_value, $nodeName ) );
            }
        }
        else
        {
            $_string = htmlspecialchars( $data, ENT_QUOTES );
        }

        //	Add the converted XML
        $_xml .= $_string;

        if ( null !== $rootName )
        {
            $_xml .= Markup::closeTag( $rootName );
        }

        return $_xml;
    }
1343273
public function setXML($key, DOMDocument $value)
    {
        $this->set(self::XML, $key, $value);

        return $this;
    }
279947
private function arrayToXml(array &$data, SimpleXMLElement $xmlData)
    {
        foreach ($data as $key => $value) {
            $key = ltrim($key, '_');

            if (\is_array($value)) {
                if (\is_numeric($key)) {
                    $key = 'resource';
                }

                if (false === empty($value[JsonTransformer::LINKS_HREF])) {
                    $subnode = $xmlData->addChild('link');
                    $subnode->addAttribute('rel', $key);

                    foreach ($this->linkKeys as $linkKey) {
                        if (!empty($value[$linkKey])) {
                            $subnode->addAttribute($linkKey, $value[$linkKey]);
                        }
                    }
                } else {
                    if (!empty($value[JsonTransformer::LINKS_KEY][JsonTransformer::LINK_SELF][JsonTransformer::LINKS_HREF])) {
                        $subnode = $xmlData->addChild('resource');
                        $subnode->addAttribute(
                            JsonTransformer::LINKS_HREF,
                            $value[JsonTransformer::LINKS_KEY][JsonTransformer::LINK_SELF][JsonTransformer::LINKS_HREF]
                        );

                        if ($key !== 'resource') {
                            $subnode->addAttribute('rel', $key);
                        }
                    } else {
                        $subnode = $xmlData->addChild($key);
                    }
                }

                $this->arrayToXml($value, $subnode);
            } else {
                if ($key !== JsonTransformer::LINKS_HREF) {
                    if ($value === true || $value === false) {
                        $value = ($value) ? 'true' : 'false';
                    }

                    $xmlData->addChild("$key", '<![CDATA['.html_entity_decode($value).']]>');
                }
            }
        }
    }
585827
public function process(\DOMDocument $xml)
    {
        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query(
            '/project/file/class/docblock/tag[@name="property"]'
            . '|/project/file/class/docblock/tag[@name="property-read"]'
            . '|/project/file/class/docblock/tag[@name="property-write"]'
        );

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            $class = $node->parentNode->parentNode;

            $property = new \DOMElement('property');
            $class->appendChild($property);

            $property->setAttribute('final', 'false');
            $property->setAttribute('static', 'false');
            $property->setAttribute('visibility', 'public');
            $property->setAttribute('line', $node->getAttribute('line'));
            $property->appendChild(
                new \DOMElement('name', $node->getAttribute('variable'))
            );
            $property->appendChild(new \DOMElement('default'));

            $docblock = new \DOMElement('docblock');
            $property->appendChild($docblock);
            $docblock->appendChild(
                new \DOMElement('description', $node->getAttribute('description'))
            );
            $docblock->appendChild(new \DOMElement('long-description'));

            $var_tag = new \DOMElement('tag');
            $docblock->appendChild($var_tag);
            $var_tag->setAttribute('name', 'var');
            $var_tag->setAttribute('description', $node->getAttribute('description'));
            $var_tag->setAttribute('type', $node->getAttribute('type'));
            $var_tag->setAttribute('line', $node->getAttribute('line'));

            $var_tag_type = new \DOMElement('type', $node->getAttribute('type'));
            $var_tag->appendChild($var_tag_type);
            $var_tag_type->setAttribute('by_reference', 'false');

            $magic_tag = new \DOMElement('tag');
            $docblock->appendChild($magic_tag);
            $magic_tag->setAttribute('name', 'magic');
            $magic_tag->setAttribute('line', $node->getAttribute('line'));

            $node->parentNode->removeChild($node);
            $docblock->appendChild($node);
        }

        return $xml;
    }
648444
public function serializeToDom($data, string $tagName = null): \DOMDocument
    {
        return $this->xmlSerializer->serialize($data, $this->xmlStreamWriter, $tagName)
               ->asDOM();
    }
582789
protected function _appendDataToNode($addCdata, Xml $xml, $key, $value)
    {
        if ($addCdata) {
            $cdata      = $xml->createCDATASection($value);
            $element    = $xml->createElement(
                $this->_integerToStringKey($key)
            );
            $element->appendChild($cdata);
        } else {
            $element = $xml->createElement(
                $this->_integerToStringKey($key),
                $value
            );
        }

        return $element;
    }
878929
protected static function data2xml($xml, $data, $item = 'item') {
        foreach ($data as $key => $value) {
            /* 指定默认的数字key */
            is_numeric($key) && $key = $item;

            /* 添加子元素 */
            if(is_array($value) || is_object($value)){
                $child = $xml->addChild($key);
                self::data2xml($child, $value, $item);
            } else {
                if(is_numeric($value)){
                    $child = $xml->addChild($key, $value);
                } else {
                    $child = $xml->addChild($key);
                    $node  = dom_import_simplexml($child);
                    $cdata = $node->ownerDocument->createCDATASection($value);
                    $node->appendChild($cdata);
                }
            }
        }
    }
483858
private function buildObject(DOMElement $data){

        $attributes = $this->extractAttributes($data);
        $returnValue = new QtiObject($attributes);

        if($data->hasChildNodes()){
            $nonEmptyChild = $this->getNonEmptyChildren($data);
            if(count($nonEmptyChild) == 1 && reset($nonEmptyChild)->nodeName == 'object'){
                $alt = $this->buildObject(reset($nonEmptyChild));
                $returnValue->setAlt($alt);
            }else{
                //get the node xml content
                $pattern = array("/^<{$data->nodeName}([^>]*)?>/i", "/<\/{$data->nodeName}([^>]*)?>$/i");
                $content = preg_replace($pattern, '', trim($this->saveXML($data)));
                $returnValue->setAlt($content);
            }
        }else{
            $alt = trim($data->nodeValue);
            if(!empty($alt)){
                $returnValue->setAlt($alt);
            }
        }

        return $returnValue;
    }
935148
public function signXML($data)
    {
        $xml = new DOMDocument;
        $xml->preserveWhiteSpace = false;
        $xml->loadXML($data);

        $sig = new DOMDocument;
        $sig->preserveWhiteSpace = false;
        $sig->loadXML(
            '<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
                <SignedInfo>
                    <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                    <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
                    <Reference URI="">
                        <Transforms>
                            <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                        </Transforms>
                        <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
                        <DigestValue/>
                    </Reference>
                </SignedInfo>
                <SignatureValue/>
                <KeyInfo><KeyName/></KeyInfo>
            </Signature>'
        );

        $sig = $xml->importNode($sig->documentElement, true);
        $xml->documentElement->appendChild($sig);

        // calculate digest
        $xpath = $this->getXPath($xml);
        $digestValue = $xpath->query('ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue')->item(0);
        $digestValue->nodeValue = $this->generateDigest($xml);

        // calculate signature
        $signedInfo = $xpath->query('ds:Signature/ds:SignedInfo')->item(0);
        $signatureValue = $xpath->query('ds:Signature/ds:SignatureValue')->item(0);
        $signatureValue->nodeValue = $this->generateSignature($signedInfo);

        // add key reference
        $keyName = $xpath->query('ds:Signature/ds:KeyInfo/ds:KeyName')->item(0);
        $keyName->nodeValue = $this->getPublicKeyDigest();

        return $xml->saveXML();
    }
84862
public function putXML($url, $data)
    {
        $responseBody = $this->put($url, $data, 'application/xml');

        return new QuiteSimpleXMLElement($responseBody);
    }
1048070
protected function processSingleProductSaleElementUpdate($data)
    {
        $event = new ProductSaleElementUpdateEvent(
            $this->getExistingObject(),
            $data['product_sale_element_id']
        );

        $event
            ->setReference($data['reference'])
            ->setPrice($data['price'])
            ->setCurrencyId($data['currency'])
            ->setWeight($data['weight'])
            ->setQuantity($data['quantity'])
            ->setSalePrice($data['sale_price'])
            ->setOnsale($data['onsale'])
            ->setIsnew($data['isnew'])
            ->setIsdefault($data['isdefault'])
            ->setEanCode($data['ean_code'])
            ->setTaxRuleId($data['tax_rule'])
            ->setFromDefaultCurrency($data['use_exchange_rate'])
        ;

        $this->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $event);

        // Log object modification
        if (null !== $changedObject = $event->getProductSaleElement()) {
            $this->adminLogAppend(
                $this->resourceCode,
                AccessManager::UPDATE,
                sprintf(
                    "Product Sale Element (ID %s) for product reference %s modified",
                    $changedObject->getId(),
                    $event->getProduct()->getRef()
                ),
                $changedObject->getId()
            );
        }
    }
1149138
protected function dataToXml($data)
    {
        if (!is_string($data)) {
            throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_PARSE_XML);
        }
        $xml = new DOMDocument();
        $error = null;
        try {
            $loaded = $xml->loadXML($data, $this->getLoadFlags());
        } catch (Exception $x) {
            $error = $x;
        } catch (Throwable $x) {
            $error = $x;
        }
        if ($error !== null || $loaded === false) {
            throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_PARSE_XML, $error ? $error->getMessage() : '');
        }

        return $xml;
    }
177271
public function loadXML($xml){
        if (!$xml){
            return false;
        }
        
        $this->data = array();
        
        //Categories first
        if ($xml->getName() == 'GetProductCategoriesForSKUResult' || $xml->getName() == 'GetProductCategoriesForASINResult'){
            $this->loadCategories($xml);
            return;
        }

        //Lowest Price uses different format
        if ($xml->getName() == 'GetLowestPricedOffersForSKUResult' || $xml->getName() == 'GetLowestPricedOffersForASINResult'){
            return $this->loadLowestPricedOfferXml($xml);
        }
        
        if ($xml->getName() != 'Product'){
            return;
        }
        
        //Identifiers
        if ($xml->Identifiers){
            foreach($xml->Identifiers->children() as $x){
                foreach($x->children() as $z){
                    $this->data['Identifiers'][$x->getName()][$z->getName()] = (string)$z;
                }
            }
        }
        
        //AttributeSets
        if ($xml->AttributeSets){
            $anum = 0;
            foreach($xml->AttributeSets->children('ns2',true) as $aset){
                foreach($aset->children('ns2',true) as $x){
                    if ($x->children('ns2',true)->count() > 0){
                        //another layer
                        foreach($x->children('ns2',true) as $y){
                            if ($y->children('ns2',true)->count() > 0){
                                //we need to go deeper
                                foreach($y->children('ns2',true) as $z){
                                    if ($z->children('ns2',true)->count() > 0){
                                        //we need to go deeper
                                        $this->log('Warning! Attribute '.$z->getName().' is too deep for this!', 'Urgent');
                                    } else {
                                        $this->data['AttributeSets'][$anum][$x->getName()][$y->getName()][$z->getName()] = (string)$z;
                                    }
                                }
                            } else {
                                $this->data['AttributeSets'][$anum][$x->getName()][$y->getName()] = (string)$y;
                            }
                        }

                    } else {
                        //Check for duplicates
                        if (array_key_exists('AttributeSets', $this->data) && 
                                array_key_exists($anum, $this->data['AttributeSets']) && 
                                array_key_exists($x->getName(), $this->data['AttributeSets'][$anum])){

                            //check for previous cases of duplicates
                            if (is_array($this->data['AttributeSets'][$anum][$x->getName()])){
                                $this->data['AttributeSets'][$anum][$x->getName()][] = (string)$x;
                            } else {
                                //first instance of duplicates, make into array
                                $temp = array($this->data['AttributeSets'][$anum][$x->getName()]);
                                $this->data['AttributeSets'][$anum][$x->getName()] = $temp;
                                $this->data['AttributeSets'][$anum][$x->getName()][] = (string)$x;
                            }
                        } else {
                            //no duplicates
                            $this->data['AttributeSets'][$anum][$x->getName()] = (string)$x;
                        }
                    }
                }
                $anum++;
            }
        }
        
        //Relationships
        if ($xml->Relationships){
            foreach($xml->Relationships->children() as $x){
                $temp = array();
                foreach($x->children() as $y){
                    foreach($y->children() as $z){
                        foreach($z->children() as $zzz){
                            $temp[$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz;
                        }
                    }
                }
                foreach($x->children('ns2',true) as $y){
                    $temp[$y->getName()] = (string)$y;
                }
                $this->data['Relationships'][$x->getName()][] = $temp;
            }
            //child relations use namespace but parent does not
            foreach($xml->Relationships->children('ns2',true) as $x){
                $temp = array();
                foreach($x->children() as $y){
                    foreach($y->children() as $z){
                        foreach($z->children() as $zzz){
                            $temp[$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz;
                        }
                    }
                }
                foreach($x->children('ns2',true) as $y){
                    $temp[$y->getName()] = (string)$y;
                }
                $this->data['Relationships'][$x->getName()][] = $temp;
            }
        }
        
        //CompetitivePricing
        if ($xml->CompetitivePricing){
            //CompetitivePrices
            foreach($xml->CompetitivePricing->CompetitivePrices->children() as $pset){
                $pnum = (string)$pset->CompetitivePriceId;
                $temp = (array)$pset->attributes();
                $belongs = $temp['@attributes']['belongsToRequester'];
                $con = $temp['@attributes']['condition'];
                $sub = $temp['@attributes']['subcondition'];
                $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['belongsToRequester'] = $belongs;
                $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['condition'] = $con;
                $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['subcondition'] = $sub;
                
                
                foreach($pset->Price->children() as $x){
                    //CompetitivePrice->Price
                    foreach($x->children() as $y){
                        $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['Price'][$x->getName()][$y->getName()] = (string)$y;
                    }
                    
                }
                
                $pnum++;
            }
            //NumberOfOfferListings
            if ($xml->CompetitivePricing->NumberOfOfferListings){
                foreach($xml->CompetitivePricing->NumberOfOfferListings->children() as $x){
                    $temp = (array)$x->attributes();
                    $att = $temp['@attributes']['condition'];
                    $this->data['CompetitivePricing']['NumberOfOfferListings'][$x->getName()][$att] = (string)$x;
                }
            }
            
            //TradeInValue
            if ($xml->CompetitivePricing->TradeInValue){
                foreach($xml->CompetitivePricing->TradeInValue->children() as $x){
                    $this->data['CompetitivePricing']['TradeInValue'][$x->getName()] = (string)$x;
                }
            }
        }
            
        
        //SalesRankings
        if ($xml->SalesRankings){
            foreach($xml->SalesRankings->children() as $x){
                $temp = array();
                foreach($x->children() as $y){
                    $temp[$y->getName()] = (string)$y;
                }
                $this->data['SalesRankings'][$x->getName()][] = $temp;
            }
        }
        
        //LowestOfferListings
        if ($xml->LowestOfferListings){
            $lnum = 0;
            foreach($xml->LowestOfferListings->children() as $x){
                //LowestOfferListing
                foreach($x->children() as $y){
                    if ($y->children()->count() > 0){
                        foreach($y->children() as $z){
                            if ($z->children()->count() > 0){
                                foreach($z->children() as $zzz){
                                    $this->data['LowestOfferListings'][$lnum][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz;
                                }
                            } else {
                                $this->data['LowestOfferListings'][$lnum][$y->getName()][$z->getName()] = (string)$z;
                            }
                            
                        }
                    } else {
                        $this->data['LowestOfferListings'][$lnum][$y->getName()] = (string)$y;
                    }
                }
                $lnum++;
            }
        }
        
        //Offers
        if ($xml->Offers){
            $onum = 0;
            foreach($xml->Offers->children() as $x){
                //Offer
                foreach($x->children() as $y){
                    if ($y->children()->count() > 0){
                        foreach($y->children() as $z){
                            if ($z->children()->count() > 0){
                                foreach($z->children() as $zzz){
                                    $this->data['Offers'][$onum][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz;
                                }
                            } else {
                                $this->data['Offers'][$onum][$y->getName()][$z->getName()] = (string)$z;
                            }
                            
                        }
                    } else {
                        $this->data['Offers'][$onum][$y->getName()] = (string)$y;
                    }
                }
                $onum++;
            }
        }
        
        
        
    }