Parses XML String and stores Channel Data and Entries.
@access		public
@param		string		$xml				XML String to parse
@param		bool		$validateRules		Validate Atom Feed against Atom Rules.
@return		void
430387
public function parse( $xml, $validateRules = TRUE )
	{
		$this->language		= "en";
		$this->channelData	= $this->emptyChannelData;
		$this->entries		= array();
			
		$root		= new XML_Element( $xml );
		if( $validateRules )
		{
			$validator	= new XML_Atom_Validator();
			if( !$validator->isValid( $root ) )	
				throw new Exception( $validator->getFirstError() );
		}

		$this->language		= $this->getNodeLanguage( $root );
		$this->channelData	= $this->parseNodes( $root, $this->emptyChannelData );
	}
1120696
public function parseXml($xmlString)
    {
        Validate::notNull($xmlString, 'xmlString');
        Validate::isString($xmlString, 'xmlString');
        $categoryXml = simplexml_load_string($xmlString);
        $attributes = $categoryXml->attributes();
        if (!empty($attributes['term'])) {
            $this->term = (string) $attributes['term'];
        }

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

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

        $this->undefinedContent = (string) $categoryXml;
    }
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++;
        }
    }
1134814
protected function parseXml($xml) {
        if (!$xml){
            return false;
        }

        $this->needByDate = null;
        if (isset($xml->NeedByDate)) {
            $this->needByDate = (string)$xml->NeedByDate;
        }
        if (isset($xml->ConfirmedNeedByDate)) {
            $this->needByDate = (string)$xml->ConfirmedNeedByDate;
        }
        $this->fulfillableDate = (string)$xml->ConfirmedFulfillableDate;
        if (isset($xml->ShipmentContainsPreorderableItems)) {
            $this->hasPreorderItems = (string)$xml->ShipmentContainsPreorderableItems;
        }
        if (isset($xml->ShipmentConfirmedForPreorder)) {
            $this->isConfirmed = (string)$xml->ShipmentConfirmedForPreorder;
        }
    }
400864
private function parseElementAttributes(DOMElement $xml)
    {
        $attrs        = [];
        $elementAttrs = $xml->xpath('./@*');

        if (0 === $elementAttrs->length) {
            return $attrs;
        }

        foreach ($elementAttrs as $key => $attribute) {
            $value = static::getPhpValue($attribute->nodeValue, null, $this);
            $name = $this->normalizeKey($attribute->nodeName);
            $attrs[$this->prefixKey($name, $attribute->prefix ?: null)] = $value;
        }

        return [$this->getAttributesKey() => $attrs];
    }
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;
    }
720362
protected function parseXml($xml){
        if (!$xml){
            return false;
        }

        $this->productList = array();
        if (!isset($xml->FeesEstimateResultList)){
            return;
        }
        foreach($xml->FeesEstimateResultList->children() as $x){
            $temp = array();
            $temp['MarketplaceId'] = (string)$x->FeesEstimateIdentifier->MarketplaceId;
            $temp['IdType'] = (string)$x->FeesEstimateIdentifier->IdType;
            $temp['IdValue'] = (string)$x->FeesEstimateIdentifier->IdValue;
            $temp['ListingPrice'] = $this->parseMoney($x->FeesEstimateIdentifier->PriceToEstimateFees->ListingPrice);
            if (isset($x->FeesEstimateIdentifier->PriceToEstimateFees->Shipping)){
                $temp['Shipping'] = $this->parseMoney($x->FeesEstimateIdentifier->PriceToEstimateFees->Shipping);
            }
            if (isset($x->FeesEstimateIdentifier->PriceToEstimateFees->Points->PointsNumber)){
                $temp['Points'] = (string)$x->FeesEstimateIdentifier->PriceToEstimateFees->Points->PointsNumber;
            }
            $temp['IsAmazonFulfilled'] = (string)$x->FeesEstimateIdentifier->IsAmazonFulfilled;
            $temp['SellerInputIdentifier'] = (string)$x->FeesEstimateIdentifier->SellerInputIdentifier;
            $temp['TimeOfFeesEstimation'] = (string)$x->FeesEstimateIdentifier->TimeOfFeesEstimation;
            $temp['Status'] = (string)$x->Status;
            if (isset($x->FeesEstimate)){
                $temp['TotalFeesEstimate'] = $this->parseMoney($x->FeesEstimate->TotalFeesEstimate);
                $temp['FeeDetailList'] = array();
                if (isset($x->FeesEstimate->FeeDetailList)){
                    foreach($x->FeesEstimate->FeeDetailList->children() as $z){
                        $temp['FeeDetailList'][] = $this->parseFeeDetail($z);
                    }
                }
            }
            if (isset($x->Error)){
                $temp['Error']['Type'] = (string)$x->Error->Type;
                $temp['Error']['Code'] = (string)$x->Error->Code;
                $temp['Error']['Message'] = (string)$x->Error->Message;
            }
            $this->productList[] = $temp;
        }
    }
919014
public function parseXml($entryXml)
    {
        $this->_entry->parseXml($entryXml);
        $content = $this->_entry->getContent();
        if (is_null($content)) {
            $this->_subscriptionDescription = null;
        } else {
            $this->_subscriptionDescription = SubscriptionDescription::create(
                $content->getText()
            );
        }
    }
116644
private function loadFromExtensions(\DOMDocument $xml)
    {
        foreach ($xml->documentElement->childNodes as $node) {
            if (!$node instanceof \DOMElement || self::NS === $node->namespaceURI) {
                continue;
            }

            $values = static::convertDomElementToArray($node);
            if (!is_array($values)) {
                $values = array();
            }

            $this->container->loadFromExtension($node->namespaceURI, $values);
        }
    }
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;
            }
        }
    }
134856
private function parseSubject(\DOMElement $xml) : void
    {
        /** @var \DOMElement[] $subject */
        $subject = Utils::xpQuery($xml, './saml_assertion:Subject');
        if (empty($subject)) {
            throw new \Exception('Missing subject in subject query.');
        } elseif (count($subject) > 1) {
            throw new \Exception('More than one <saml:Subject> in subject query.');
        }

        /** @var \DOMElement[] $nameId */
        $nameId = Utils::xpQuery($subject[0], './saml_assertion:NameID');
        if (empty($nameId)) {
            throw new \Exception('Missing <saml:NameID> in <saml:Subject>.');
        } elseif (count($nameId) > 1) {
            throw new \Exception('More than one <saml:NameID> in <saml:Subject>.');
        }
        $this->nameId = new NameID($nameId[0]);
    }
167501
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        
        foreach($xml->children() as $x){
            if($x->getName() == 'ResponseMetadata'){
                continue;
            }
            $temp = (array)$x->attributes();
            if (isset($temp['@attributes']['status']) && $temp['@attributes']['status'] != 'Success'){
                $this->log("Warning: product return was not successful",'Warning');
            }
            if (isset($x->Products)){
                foreach($x->Products->children() as $z){
                    $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, $this->mockFiles,$this->config);
                    if (isset($temp['@attributes'])) {
                        $this->productList[$this->index]->data['Identifiers']['Request'] = $temp['@attributes'];
                    }
                    $this->index++;
                }
            } else if (in_array($x->getName(), array('GetProductCategoriesForSKUResult', 'GetProductCategoriesForASINResult',
                    'GetLowestPricedOffersForSKUResult', 'GetLowestPricedOffersForASINResult'))){
                $this->productList[$this->index] = new AmazonProduct($this->storeName, $x, $this->mockMode, $this->mockFiles,$this->config);
                $this->index++;
            } else {
                foreach($x->children() as $z){
                    if($z->getName() == 'Error'){
                        $error = (string)$z->Message;
                        $this->productList['Error'] = $error;
                        $this->log("Product Error: $error",'Warning');
                    } elseif($z->getName() != 'Product'){
                        $this->productList[$z->getName()] = (string)$z;
                        $this->log("Special case: ".$z->getName(),'Warning');
                    } else {
                        $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, $this->mockFiles,$this->config);
                        $this->index++;
                    }
                }
            }
        }
    }
705556
public static function validar($xml, $schemaFile)
    {
        //Para poder pegar os erros caso houver
        libxml_use_internal_errors(true);
        libxml_clear_errors();

        if (is_file($xml)) {
            $xml = file_get_contents($xml);
        }

        $dom = new DOMDocument('1.0', 'utf-8');

        $dom->loadXML($xml, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);

        if (! $dom->schemaValidate($schemaFile)) {
            $errors = libxml_get_errors();
            $returnErrors = [];
            foreach ($errors as $error) {
                $returnErrors[] = $error->message . 'at line ' . $error->line;
            }

            $msg = "Erro ao validar XML:\r\n" . implode("\r\n", $returnErrors);

            throw new \Exception($msg);
        }

        return true;
    }
1259040
public function validateDataWithRules(array $data, array $validateRules, array $validateMessages = [], array $parametricConverter = [])
    {
        foreach ($validateRules as $key => $rules) {
            $value = array_key_exists($key, $data) ? $data[$key] : null;

            if (array_key_exists('nullable', $rules) && $rules['nullable'] && is_null($value)) {
                continue;
            }

            unset($rules['nullable']);

            $defaultParametricConverter = (method_exists($this, 'getParametricConverter') && is_array($this->getParametricConverter())) ? $this->getParametricConverter() : [];
            $parametricConverter = array_merge($defaultParametricConverter, $parametricConverter);
            $parameter = (array_key_exists($key, $parametricConverter)) ? $parametricConverter[$key] : $key;

            foreach ($rules as $ruleName => $ruleParameter) {
                if ($ruleName === 'callback') {
                    if (!is_callable($ruleParameter)) {
                        throw new BadMethodCallException('The reference of rule named `callback` must be a valid callable. You provided ' . $this->getValueDescription($ruleParameter) . '.');
                    }

                    call_user_func($ruleParameter, $value, InvalidRequestException::class);
                } else {
                    $method = 'check'.ucfirst(Helper::camelCase($ruleName));

                    if (!method_exists($this, $method)) {
                        throw new BadMethodCallException('Call to undefined the ' .get_class($this). '::' .$method. '() validator that associated with the `' .$ruleName. '` rule');
                    }

                    if (!$this->$method($value, $ruleParameter)) {
                        $message = isset($validateMessages[$key][$ruleName]) ? $validateMessages[$key][$ruleName] : null;

                        throw new InvalidRequestException($this->formatMessage($parameter, $ruleName, $ruleParameter, $message));
                    }
                }
            }
        }
    }
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;
    }
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++;
        }
    }
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;
    }