Validates XML File.
@access		public
@param		string		$xml		XML String to validate
@return		bool
187054
public function validate( $xml )
	{
		$parser	= xml_parser_create();
		$dummy	= create_function( '', '' );
		xml_set_element_handler( $parser, $dummy, $dummy );
		xml_set_character_data_handler( $parser, $dummy );
		if( !xml_parse( $parser, $xml ) )
		{
			$msg	= "%s at line %d";
			$error	= xml_error_string( xml_get_error_code( $parser ) );
			$line	= xml_get_current_line_number( $parser );
			$this->error['message']	= sprintf( $msg, $error, $line );
			$this->error['line']	= $line;
			$this->error['xml']		= $xml;
			xml_parser_free( $parser );
			return FALSE;
		}
		xml_parser_free( $parser );
		return TRUE;
	}
283749
public function validate($value)
    {
        if (!$value instanceof DOMDocument) {
            $this->errors[] = TypeValidationError::xmlValidationFailed('Expected value of type DOMDocument');

            return;
        }

        $originalErrorLevel = \libxml_use_internal_errors(true);
        $value->schemaValidateSource($this->xml);
        $errors = \libxml_get_errors();
        \libxml_clear_errors();
        if ($errors) {
            foreach ($errors as $error) {
                $this->errors[] = TypeValidationError::xmlValidationFailed($error->message);
            }

            return;
        }

        \libxml_use_internal_errors($originalErrorLevel);
    }
21082
public function validate($xml)
    {
        $errors = [];

        // Enable custom error handling.
        $previousInternalErrorsFlag = libxml_use_internal_errors(true);

        // Clear errors from previous classes, if any.
        libxml_clear_errors();

        $xmlDocument = new \DOMDocument();
        $xmlDocument->loadXML($xml);

        $xsd = $this->xsdReader->read();

        if (!$xmlDocument->schemaValidateSource($xsd->getContent())) {
            $libXMLErrors = array_filter(
                libxml_get_errors(),
                function (\LibXMLError $libXMLError) {
                    return $libXMLError->level >= $this->minimumReportLevel;
                }
            );

            $libXMLErrors = array_values($libXMLErrors);

            $errors = array_map(
                function (\LibXMLError $libXMLError) {
                    return new XMLValidationError(
                        rtrim($libXMLError->message),
                        $libXMLError->line,
                        $libXMLError->column
                    );
                },
                $libXMLErrors
            );

            // Clear errors for any future validations or other classes.
            libxml_clear_errors();
        }

        libxml_use_internal_errors($previousInternalErrorsFlag);

        return $errors;
    }
202125
public function parseXML($xml)
    {
        $document = new \DOMDocument();

        $previousValue = libxml_use_internal_errors(true);
        libxml_clear_errors();
        $result = $document->loadXML($xml);
        /** @var \libXMLError[] $errors */
        $errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($previousValue);

        if (true !== $result) {
            $message = [];
            foreach ($errors as $error) {
                $message[] = sprintf(
                    '%d. [%s] %s in on line %d in position %d',
                    count($message) + 1,
                    $error->code,
                    str_replace(["\n", "\r"], '', $error->message),
                    $error->line,
                    $error->column
                );
            }
            throw new RuntimeException('Can not parse XML: ' . implode('; ', $message));
        }

        return $this->parseDocument($document);
    }
769060
protected static function xml2Data($xml)
    {
        $result = null;
        is_object($xml) && $xml = (array)$xml;
        if (is_array($xml)) {
            foreach ($xml as $key => $value) {
                $res = static::xml2Data($value);
                if (('@attributes' === $key) && ($key)) {
                    $result = $res;
                } else {
                    $result[$key] = $res;
                }
            }
        } else {
            $result = $xml;
        }
        return $result;
    }
1307838
public static function cleanXML($xml)
    {
        if($xml != '') {
            $doc = new \DOMDocument();
            $doc->loadXML($xml);
            $doc->formatOutput = true;
            return $doc->saveXML();
        } else {
            return '';
        }
    }
1281710
protected function generateXMLObject($xml)
    {
        try {
            libxml_use_internal_errors(true);
            return new SimpleXMLElement($xml, LIBXML_NOCDATA);
        } catch (\Exception $e) {
            return false;
        }
    }
559080
public static function isValidXml($xml, $doc = null)
    {
        if ($doc == null) {
            $doc = new DOMDocument("1.0", "ISO-8859-1");
        }

        // tries to load the document and gets the errors
        $useInternalErrors = libxml_use_internal_errors(true);
        $doc->loadXML($xml);
        $errors = libxml_get_errors();
        libxml_use_internal_errors($useInternalErrors);

        return count($errors) == 0;
    }
1045077
public function validate($xmlString, $xsdFile)
    {
        libxml_use_internal_errors(true);

        $xml = new \DOMDocument();
        $xml->loadXML($xmlString);

        if (!$xml->schemaValidate($xsdFile)) {
            $messages = [];
            foreach (libxml_get_errors() as $error) {
                array_push($messages, sprintf('%s in line %d', $error->message, $error->line));
            }
            libxml_clear_errors();

            throw new XsdValidationException(implode(PHP_EOL, $messages));
        }

        return true;
    }
420000
private function getError(string $xml)
    {
        if ([] !== ($errors = libxml_get_errors())) {
            libxml_clear_errors();
            return new XmlException($errors, sprintf("Invalid xml string \n\n%s\n", $xml));
        }
        return null;
    }
811617
protected function parseXml($xml) {
        if (!$xml){
            return false;
        }

        //SKU or ASIN list
        $list = false;
        if (isset($xml->SKUPrepInstructionsList)) {
            $list = $xml->SKUPrepInstructionsList;
        }
        if (isset($xml->ASINPrepInstructionsList)) {
            $list = $xml->ASINPrepInstructionsList;
        }
        if ($list) {
            foreach ($list->children() as $x) {
                $temp = array();
                if (isset($x->SellerSKU)) {
                    $temp['SellerSKU'] = (string)$x->SellerSKU;
                }
                $temp['ASIN'] = (string)$x->ASIN;
                $temp['BarcodeInstruction'] = (string)$x->BarcodeInstruction;
                $temp['PrepGuidance'] = (string)$x->PrepGuidance;
                foreach ($x->PrepInstructionList->children() as $z) {
                    $temp['PrepInstructionList'][] = (string)$z;
                }
                if (isset($x->AmazonPrepFeesDetailsList)) {
                    foreach ($x->AmazonPrepFeesDetailsList->children() as $z) {
                        $fee = array();
                        $fee['PrepInstruction'] = (string)$z->PrepInstruction;
                        $fee['Amount']['Value'] = (string)$z->Amount->Value;
                        $fee['Amount']['CurrencyCode'] = (string)$z->Amount->CurrencyCode;
                        $temp['AmazonPrepFees'][] = $fee;
                    }
                }
                $this->prepList[] = $temp;
            }
        }

        //invalid item list
        $invList = false;
        if (isset($xml->InvalidSKUList)) {
            $invList = $xml->InvalidSKUList;
        }
        if (isset($xml->InvalidASINList)) {
            $invList = $xml->InvalidASINList;
        }
        if ($invList) {
            foreach ($invList->children() as $x) {
                $temp = array();
                $temp['ErrorReason'] = (string)$x->ErrorReason;
                if (isset($x->SellerSKU)) {
                    $temp['SellerSKU'] = (string)$x->SellerSKU;
                }
                if (isset($x->ASIN)) {
                    $temp['ASIN'] = (string)$x->ASIN;
                }
                $this->invalidList[] = $temp;
            }
        }
    }
1030442
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        foreach($xml->ShipmentData->children() as $x){
            $a = array();

            if (isset($x->ShipmentId)){
                $a['ShipmentId'] = (string)$x->ShipmentId;
            }
            if (isset($x->ShipmentName)){
                $a['ShipmentName'] = (string)$x->ShipmentName;
            }

            //Address
            $a['ShipFromAddress']['Name'] = (string)$x->ShipFromAddress->Name;
            $a['ShipFromAddress']['AddressLine1'] = (string)$x->ShipFromAddress->AddressLine1;
            if (isset($x->ShipFromAddress->AddressLine2)){
                $a['ShipFromAddress']['AddressLine2'] = (string)$x->ShipFromAddress->AddressLine2;
            } else {
                $a['ShipFromAddress']['AddressLine2'] = null;
            }
            $a['ShipFromAddress']['City'] = (string)$x->ShipFromAddress->City;
            if (isset($x->ShipFromAddress->DistrictOrCounty)){
                $a['ShipFromAddress']['DistrictOrCounty'] = (string)$x->ShipFromAddress->DistrictOrCounty;
            } else {
                $a['ShipFromAddress']['DistrictOrCounty'] = null;
            }
            $a['ShipFromAddress']['StateOrProvinceCode'] = (string)$x->ShipFromAddress->StateOrProvinceCode;
            $a['ShipFromAddress']['CountryCode'] = (string)$x->ShipFromAddress->CountryCode;
            $a['ShipFromAddress']['PostalCode'] = (string)$x->ShipFromAddress->PostalCode;

            if (isset($x->DestinationFulfillmentCenterId)){
                $a['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId;
            }
            if (isset($x->LabelPrepType)){
                $a['LabelPrepType'] = (string)$x->LabelPrepType;
            }
            if (isset($x->ShipmentStatus)){
                $a['ShipmentStatus'] = (string)$x->ShipmentStatus;
            }

            $a['AreCasesRequired'] = (string)$x->AreCasesRequired;

            if (isset($x->ConfirmedNeedByDate)){
                $a['ConfirmedNeedByDate'] = (string)$x->ConfirmedNeedByDate;
            }
            
            $this->shipmentList[$this->index] = $a;
            $this->index++;
        }
    }
1048532
protected function parseXML($xml){
        $this->destinationList = array();
        if (!$xml){
            return false;
        }

        $i = 0;
        foreach ($xml->DestinationList->children() as $item) {
            $this->destinationList[$i]['DeliveryChannel'] = (string)$item->DeliveryChannel;

            foreach ($item->AttributeList->children() as $member) {
                $this->destinationList[$i]['AttributeList'][(string)$member->Key] = (string)$member->Value;
            }

            $i++;
        }
    }
1331695
public function validate(DOMDocument $xml)
    {
        $errors = [];

        $xpath = new DOMXPath($xml);
        foreach ($xpath->query('//link') as $link) {
            if ($link->hasAttribute('object_id')) {
                $objectId = $link->getAttribute('object_id');
                if ($objectId && !$this->validateEzObject($objectId)) {
                    $errors[] = $this->getInvalidLinkError('ezobject', $objectId, $link->getAttribute('anchor_name'));
                }
            } elseif ($link->hasAttribute('node_id')) {
                $nodeId = $link->getAttribute('node_id');
                if ($nodeId && !$this->validateEzNode($nodeId)) {
                    $errors[] = $this->getInvalidLinkError('eznode', $nodeId, $link->getAttribute('anchor_name'));
                }
            }
        }

        return $errors;
    }
23520
public function dontSeeXmlResponseIncludes($xml)
    {
        $this->assertStringNotContainsString(
            XmlUtils::toXml($xml)->C14N(),
            XmlUtils::toXml($this->connectionModule->_getResponseContent())->C14N(),
            "found in XML Response"
        );
    }
41424
protected function loadXML($xml)
	{
		$this->checkUnsupported($xml);

		// Activate small nodes allocation and relax LibXML's hardcoded limits if applicable. Limits
		// on tags can be set during configuration
		$flags = (LIBXML_VERSION >= 20700) ? LIBXML_COMPACT | LIBXML_PARSEHUGE : 0;

		$useErrors = libxml_use_internal_errors(true);
		$dom       = new DOMDocument;
		$success   = $dom->loadXML($xml, $flags);
		libxml_use_internal_errors($useErrors);

		if (!$success)
		{
			throw new InvalidArgumentException('Cannot load XML: ' . libxml_get_last_error()->message);
		}

		return $dom;
	}
649682
public function validateXML($xml)
    {
        $xmlValidator = new XMLValidator();
        $result = $xmlValidator->validateSchemaVersion($xml);
        if ($result === false) {
            $this->setResponse("verbosemessage", $xmlValidator->getValidationMessage());
            return false;
        }
        return true;
    }