A
A
Alexander2018-02-23 23:31:03
PHP
Alexander, 2018-02-23 23:31:03

How to access values ​​in a tag?

There is a response from the Russian Post API. SOAP in xml format, with repeated tags. Loading each repetition into an array. Each cell has a few more tags, information from which I want to pick up. Tell me, is there an easier option than "research" of each internal tag?
The cell looks like this:

<ns3:AddressParameters><ns3:DestinationAddress><ns3:Index>690034</ns3:Index><ns3:Description>Владивосток 34</ns3:Description></ns3:DestinationAddress><ns3:OperationAddress><ns3:Index>124575</ns3:Index><ns3:Description>Москва 575</ns3:Description></ns3:OperationAddress><ns3:MailDirect><ns3:Id>643</ns3:Id><ns3:Code2A>RU</ns3:Code2A><ns3:Code3A>RUS</ns3:Code3A><ns3:NameRU>Российская Федерация</ns3:NameRU><ns3:NameEN>Russian Federation</ns3:NameEN></ns3:MailDirect><ns3:CountryOper><ns3:Id>643</ns3:Id><ns3:Code2A>RU</ns3:Code2A><ns3:Code3A>RUS</ns3:Code3A><ns3:NameRU>Российская Федерация</ns3:NameRU><ns3:NameEN>Russian Federation</ns3:NameEN></ns3:CountryOper></ns3:AddressParameters><ns3:FinanceParameters><ns3:Payment>0</ns3:Payment><ns3:Value>0</ns3:Value><ns3:MassRate>33000</ns3:MassRate><ns3:InsrRate>0</ns3:InsrRate><ns3:AirRate>0</ns3:AirRate><ns3:Rate>0</ns3:Rate><ns3:CustomDuty>0</ns3:CustomDuty></ns3:FinanceParameters><ns3:ItemParameters><ns3:Barcode>12457517009036</ns3:Barcode><ns3:ValidRuType>false</ns3:ValidRuType><ns3:ValidEnType>false</ns3:ValidEnType><ns3:ComplexItemName>Посылка обыкновенная</ns3:ComplexItemName><ns3:MailRank><ns3:Id>0</ns3:Id><ns3:Name>Без разряда</ns3:Name></ns3:MailRank><ns3:PostMark><ns3:Id>2048</ns3:Id><ns3:Name>Нестандартная</ns3:Name></ns3:PostMark><ns3:MailType><ns3:Id>4</ns3:Id><ns3:Name>Посылка</ns3:Name></ns3:MailType><ns3:MailCtg><ns3:Id>3</ns3:Id><ns3:Name>Обыкновенное</ns3:Name></ns3:MailCtg><ns3:Mass>441</ns3:Mass></ns3:ItemParameters><ns3:OperationParameters><ns3:OperType><ns3:Id>1</ns3:Id><ns3:Name>Прием</ns3:Name></ns3:OperType><ns3:OperAttr><ns3:Id>1</ns3:Id><ns3:Name>Единичный</ns3:Name></ns3:OperAttr><ns3:OperDate>2017-12-26T16:00:32.000+03:00</ns3:OperDate></ns3:OperationParameters><ns3:UserParameters><ns3:SendCtg><ns3:Id>1</ns3:Id><ns3:Name>Население</ns3:Name></ns3:SendCtg></ns3:UserParameters>

I would like to take the values ​​through the request: AddressParameters->DestinationAddress->Index
ps I feel that the solution is on the surface, but stuck ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-04-06
@SilimAl

If anyone needs it..

$xmlstr = $client->__doRequest($request, "https://tracking.russianpost.ru/rtm34", "getOperationHistory", SOAP_1_2);
$xml = simplexml_load_string($xmlstr);
$items = $xml->children('S', true)->Body->children('ns7', true)->getOperationHistoryResponse->children('ns3', true)->OperationHistoryData->historyRecord;

Then we take what we need
$datetime = $item->OperationParameters->OperDate;
$nameoperattr = $item->OperationParameters->OperAttr->Name;

J
JhaoDa, 2018-02-23
@JhaoDa

Make your life easier - use https://github.com/appwilio/russianpost-sdk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question