Generate XML request

@param DOMDocument $xmlRequest XML request to parse to plain XML

@return string
965020
private function plainXML($xmlRequest)
    {
        $envelope = new DOMDocument();
        $envelope->loadXML(
            '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
		    <soapenv:Body></soapenv:Body>
		</soapenv:Envelope>'
        );

        $envelope->encoding = 'UTF-8';
        $envelope->version = '1.0';
        $xmlRequestType = $xmlRequest->documentElement->localName;
        $xmlRequestTypeNode = $xmlRequest->getElementsByTagName($xmlRequestType)->item(0);
        $xmlRequestTypeNode = $envelope->importNode($xmlRequestTypeNode, true);

        $envelope->getElementsByTagName('Body')->item(0)->appendChild($xmlRequestTypeNode);

        return $envelope->saveXML();
    }
620140
private function _asXml($simpleXml)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->loadXML($simpleXml->asXML());
        $dom->formatOutput = true;

        return $dom->saveXML();
    }
934499
public function createResponseFromXml($xml)
    {
        $dom = new \DomDocument($xml);
        if (!$dom->loadXML($xml)) {
            return;
        }

        $data = array();

        foreach($dom->childNodes as $root) {
            if ($root->nodeType !== XML_ELEMENT_NODE) {
                continue;
            }
            foreach($root->childNodes as $node) {
                $name = $node->nodeName;
                $text = $node->textContent;
                $data[$name] = $text;
            }
        }

        return new Response($data);
    }
155408
public function convert(DOMDocument $xmlDoc)
    {
        $xpath = new DOMXPath($xmlDoc);

        $elements = $xpath->query('//link|//embed|//embed-inline');

        /** @var \DOMElement $element */
        foreach ($elements as $element) {
            $location = null;

            if ($this->elementHasAttribute($element, 'object_id')) {
                try {
                    $contentInfo = $this->contentService->loadContentInfo(
                        $this->getElementAttribute($element, 'object_id')
                    );
                    $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->warning(
                            'While generating links for xmltext, could not locate ' .
                            'Content object with ID ' . $this->getElementAttribute($element, 'object_id')
                        );
                    }
                } catch (APIUnauthorizedException $e) {
                    if ($this->logger) {
                        $this->logger->notice(
                            'While generating links for xmltext, unauthorized to load ' .
                            'Content object with ID ' . $this->getElementAttribute($element, 'object_id')
                        );
                    }
                }
            }

            if ($this->elementHasAttribute($element, 'node_id')) {
                try {
                    $location = $this->locationService->loadLocation(
                        $this->getElementAttribute($element, 'node_id')
                    );
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->warning(
                            'While generating links for xmltext, could not locate ' .
                            'Location with ID ' . $this->getElementAttribute($element, 'node_id')
                        );
                    }
                } catch (APIUnauthorizedException $e) {
                    if ($this->logger) {
                        $this->logger->notice(
                            'While generating links for xmltext, unauthorized to load ' .
                            'Location with ID ' . $this->getElementAttribute($element, 'node_id')
                        );
                    }
                }
            }

            if ($location !== null) {
                $element->setAttribute('url', $this->urlAliasRouter->generate($location));
            }

            // Copy temporary URL if it exists and is not set at this point
            if (!$element->hasAttribute('url') && $element->hasAttribute(EmbedLinking::TEMP_PREFIX . 'url')) {
                $element->setAttribute('url', $element->getAttribute(EmbedLinking::TEMP_PREFIX . 'url'));
            }

            if ($this->elementHasAttribute($element, 'anchor_name')) {
                $anchor = '#' . $this->getElementAttribute($element, 'anchor_name');
                if (strpos($element->getAttribute('url'), $anchor) === false) {
                    $element->setAttribute(
                        'url',
                        $element->getAttribute('url') . '#' .
                        $this->getElementAttribute($element, 'anchor_name')
                    );
                }
            }
        }
    }
179006
public function parseXml($xmlString)
    {
        $generatorXml = new \SimpleXMLElement($xmlString);
        $attributes = $generatorXml->attributes();
        if (!empty($attributes['uri'])) {
            $this->uri = (string) $attributes['uri'];
        }

        if (!empty($attributes['version'])) {
            $this->version = (string) $attributes['version'];
        }

        $this->text = (string) $generatorXml;
    }
370247
protected function getXmlString()
    {
        if ($this->getTransactionReference() || $this->getCardReference()) {
            $xmlRoot = 'ccStoredDataRequestV1';
        } else {
            $xmlRoot = 'ccAuthRequestV1';
        }

        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
                <{$xmlRoot}
                    xmlns=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\"
                    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
                    xsi:schemaLocation=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\" />";

        $sxml = new \SimpleXMLElement($xml);

        $merchantAccount = $sxml->addChild('merchantAccount');

        $merchantAccount->addChild('accountNum', $this->getAccountNumber());
        $merchantAccount->addChild('storeID', $this->getStoreId());
        $merchantAccount->addChild('storePwd', $this->getStorePassword());

        $sxml->addChild('merchantRefNum', $this->getCustomerId() ?: 'ref-num - ' . time());

        if ($this->getTransactionReference() || $this->getCardReference()) {
            $sxml->addChild('confirmationNumber', $this->getTransactionReference() ?: $this->getCardReference());
            $sxml->addChild('amount', $this->getAmount());
        } else {
            /** @var $card CreditCard */
            $card = $this->getCard();

            $sxml->addChild('amount', $this->getAmount());

            $cardChild = $sxml->addChild('card');

            $cardChild->addChild('cardNum', $card->getNumber());

            $cardExpiry = $cardChild->addChild('cardExpiry');
            $cardExpiry->addChild('month', $card->getExpiryDate('m'));
            $cardExpiry->addChild('year', $card->getExpiryDate('Y'));

            $cardChild->addChild('cardType', $this->translateCardType($card->getBrand()));
            $cardChild->addChild('cvdIndicator', '1');
            $cardChild->addChild('cvd', $card->getCvv());

            $billingDetails = $sxml->addChild('billingDetails');

            $billingDetails->addChild('cardPayMethod', 'WEB');
            $billingDetails->addChild('firstName', $card->getBillingFirstName());
            $billingDetails->addChild('lastName', $card->getBillingLastName());
            $billingDetails->addChild('street', $card->getBillingAddress1());
            $billingDetails->addChild('street2', $card->getBillingAddress2());
            $billingDetails->addChild('city', $card->getBillingCity());
            $billingDetails->addChild('state', $card->getBillingState());
            $billingDetails->addChild('country', $card->getBillingCountry());
            $billingDetails->addChild('zip', $card->getBillingPostcode());
            $billingDetails->addChild('phone', $card->getBillingPhone());
            $billingDetails->addChild('email', $card->getEmail());

            $shippingDetails = $sxml->addChild('shippingDetails');

            $shippingDetails->addChild('firstName', $card->getShippingFirstName());
            $shippingDetails->addChild('lastName', $card->getShippingLastName());
            $shippingDetails->addChild('street', $card->getShippingAddress1());
            $shippingDetails->addChild('street2', $card->getShippingAddress2());
            $shippingDetails->addChild('city', $card->getShippingCity());
            $shippingDetails->addChild('state', $card->getShippingState());
            $shippingDetails->addChild('country', $card->getShippingCountry());
            $shippingDetails->addChild('zip', $card->getShippingPostcode());
            $shippingDetails->addChild('phone', $card->getShippingPhone());
            $shippingDetails->addChild('email', $card->getEmail());
        }

        return $sxml->asXML();
    }
752337
public static function parse($xml, $section = null)
  {
    $parser = new XMLParser($xml);
    if (is_string($section) && !empty($section)) {
      return $parser->getXml()->get($section, true);
    }
    return $parser->getXml();
  }
63136
protected function xmlToData(DOMDocument $xml)
    {
        $data = $xml->saveXML();
        if ($data === false) {
            throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_GENERATE_XML);
        }

        return $data;
    }
177522
private function generateResponse($request)
    {
        $context  = stream_context_create(
            array(
                'http' => array(
                    'method'  => "POST",
                    'header'  => "Content-Type: text/xml",
                    'content' => $request
                )
            )
        );
        $file     = file_get_contents(self::SEARCH_URL, false, $context);
        $response = xmlrpc_decode($file);

        return $response;
    }
17370
private function postXML($xml, $url)
    {
        if ($this->config['queue']) {
            Queue::push(function () use ($xml, $url) {
                $client = new Client();
                $request = new Request('POST', $url, ['Content-Type' => 'text/xml; charset=UTF8'], $xml);
                $response = $client->send($request);
                return $response->getBody()->getContents();
            });
        } else {
            $client = new Client();
            $request = new Request('POST', $url, ['Content-Type' => 'text/xml; charset=UTF8'], $xml);
            $response = $client->send($request);
            return $response->getBody()->getContents();
        }
    }
1153547
public static function createFromXml(SimpleXMLElement $xmlAddress)
    {
        $address = new DTO\Address();

        if (isset($xmlAddress->Ctry)) {
            $address = $address->setCountry((string) $xmlAddress->Ctry);
        }
        if (isset($xmlAddress->CtrySubDvsn)) {
            $address = $address->setCountrySubDivision((string) $xmlAddress->CtrySubDvsn);
        }
        if (isset($xmlAddress->Dept)) {
            $address = $address->setDepartment((string) $xmlAddress->Dept);
        }
        if (isset($xmlAddress->SubDept)) {
            $address = $address->setSubDepartment((string) $xmlAddress->SubDept);
        }
        if (isset($xmlAddress->StrtNm)) {
            $address = $address->setStreetName((string) $xmlAddress->StrtNm);
        }
        if (isset($xmlAddress->BldgNb)) {
            $address = $address->setBuildingNumber((string) $xmlAddress->BldgNb);
        }
        if (isset($xmlAddress->PstCd)) {
            $address = $address->setPostCode((string) $xmlAddress->PstCd);
        }
        if (isset($xmlAddress->TwnNm)) {
            $address = $address->setTownName((string) $xmlAddress->TwnNm);
        }
        if (isset($xmlAddress->AdrLine)) {
            foreach ($xmlAddress->AdrLine as $line) {
                $address = $address->addAddressLine((string)$line);
            }
        }

        return $address;
    }
202791
private function createRawXmlDocument()
    {
        $xmlDocument = new \DOMDocument;
        $xmlDocument->encoding = 'UTF-8';
        $xmlDocument->strictErrorChecking = false;
        $xmlDocument->formatOutput = true;
        $libXmlState = libxml_use_internal_errors(true);
        $xmlDocument->loadHTML($this->getUnifiedHtml());
        libxml_clear_errors();
        libxml_use_internal_errors($libXmlState);
        $xmlDocument->normalizeDocument();

        return $xmlDocument;
    }
417577
protected function createResponse($xml)
    {
        $requestClass = get_class($this);
        $responseClass = substr($requestClass, 0, -7) . 'Response';
        return $this->response = new $responseClass($this, $xml);
    }
747476
function inputXML( )
    {
        $node = null;
        $dom = new DOMDocument( '1.0', 'utf-8' );
        $success = false;
        if ( $this->XMLData )
        {
            $success = $dom->loadXML( $this->XMLData );
        }

        eZDebugSetting::writeDebug( 'kernel-datatype-ezxmltext',
                                    $this->XMLData,
                                    __METHOD__ . ' xml string stored in database' );

        $output = '';
        $browserEngineName = self::browserSupportsDHTMLType();

        if ( $success )
        {
            $rootSectionNode = $dom->documentElement;
            $output .= $this->inputSectionXML( $rootSectionNode, 0 );
        }

        if ( $browserEngineName === 'Trident' )
        {
            $output = str_replace( '<p></p>', '<p>&nbsp;</p>', $output );
        }
        else /* if ( $browserEngineName !== 'Presto' ) */
        {
            $output = str_replace( '<p></p>', '<p><br /></p>', $output );
        }

        $output = str_replace( array( "\n", "\xC2\xA0" ), array( '', '&nbsp;' ), $output );

        if ( $output )
        {
            if ( $browserEngineName === 'Trident' )
            {
                $output .= '<p>&nbsp;</p>';
            }
            else
            {
                $output .= '<p><br /></p>';
            }
        }

        eZDebugSetting::writeDebug( 'kernel-datatype-ezxmltext',
                                    $output,
                                    __METHOD__ . ' xml output to return' );

        $output = htmlspecialchars( $output, ENT_COMPAT, 'UTF-8' );

        return $output;
    }
1217424
function inputXML()
    {
        $contentObjectAttribute = $this->ContentObjectAttribute;
        $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );

        $originalInput = 'originalInput_' . $contentObjectAttributeID;
        $isInputValid = 'isInputValid_' . $contentObjectAttributeID;

        if ( isset( $GLOBALS[$isInputValid] ) and $GLOBALS[$isInputValid] == false )
        {
            $output = $GLOBALS[$originalInput];
        }
        else
        {
            $dom = new DOMDocument( '1.0', 'utf-8' );
            $success = $dom->loadXML( $this->XMLData );

            $editOutput = new eZSimplifiedXMLEditOutput();
            $dom->formatOutput = true;
            if ( eZDebugSetting::isConditionTrue( 'kernel-datatype-ezxmltext', eZDebug::LEVEL_DEBUG ) )
                eZDebug::writeDebug( $dom->saveXML(), eZDebugSetting::changeLabel( 'kernel-datatype-ezxmltext', __METHOD__ . ' xml string stored in database' ) );
            $output = $editOutput->performOutput( $dom );
        }
        return $output;
    }
1052707
public static function GetRemoteXMLDocument($url)
	{
		// THIS FUNCTION IS A CRAP!!!!
		// I NEED REFACTORY THIS!
		$handle = FileUtil::OpenRemoteDocument($url);
		$xmlString = FileUtil::ReadRemoteDocument($handle);

		$search = array ("'&(quot|#34);'i",                 // Replace HTML entities
		                 "'&(amp|#38);'i",
		                 //"'&(lt|#60);'i",
		                 //"'&(gt|#62);'i",
		                 "'&(nbsp|#160);'i",
		                 "'&(iexcl|#161);'i",
		                 "'&(cent|#162);'i",
		                 "'&(pound|#163);'i",
		                 "'&(copy|#169);'i",
		                 "'&aacute;'i",
		                 "'&eacute;'i",
		                 "'&iacute;'i",
		                 "'&oacute;'i",
		                 "'&uacute;'i",
		                 "'&atilde;'i",
		                 "'&ccedil;'i",
		                 "'&#(\d+);'e");                    // evaluate as php

		$replace = array ("\"",
		                  "&",
		                  //"<",
		                  //">",
		                  " ",
		                  chr(161),
		                  chr(162),
		                  chr(163),
		                  chr(169),
		                  "á",
		                  "é",
		                  "í",
		                  "ó",
		                  "ú",
		                  "ã",
		                  "ç",
		                  "chr(\\1)");


		$xmlString = preg_replace($search, $replace, $xmlString);
		//$xmlString = tidy_parse_string($xmlString, array('output-xml' => TRUE), 'UTF8');

		$xmldoc = XmlUtil::CreateXmlDocumentFromStr($xmlString);

		return $xmldoc;
	}
638238
public static function xmlArray($xml)
    {
        $dom = simplexml_load_file($xml);
        $json_encode = json_encode($dom);
        $json_decode = json_decode($json_encode, true);

        return $json_decode;
    }