@RobertoB24

Как в браузере отобразить полученый ответ xml?

Пожалуйста помогите решением.
Я получаю хml ответ в консоли браузера.

<?xml version="1.0" encoding="UTF-8"?>
<root><success>true</success><data><item><Number>59000372690877</Number><DateCreated>23-10-2018 16:20:34</DateCreated><DocumentWeight>6</DocumentWeight><CheckWeight>0</CheckWeight><DocumentCost>71</DocumentCost><SumBeforeCheckWeight>0</SumBeforeCheckWeight><PayerType>Recipient</PayerType><RecipientFullName></RecipientFullName><RecipientDateTime>26.10.2018 14:00:31</RecipientDateTime><OwnerDocumentType></OwnerDocumentType><ScheduledDeliveryDate>26-10-2018</ScheduledDeliveryDate><PaymentMethod>Cash</PaymentMethod><CargoDescriptionString></CargoDescriptionString><CargoType>Parcel</CargoType><CitySender>Чернігів</CitySender><CityRecipient>Марківка</CityRecipient><WarehouseSender>Відділення №1: вул. Старобілоуська, 77</WarehouseSender><WarehouseRecipient>Відділення: вул. Лермонтова, 18</WarehouseRecipient><CounterpartyType>PrivatePerson</CounterpartyType><Redelivery>1</Redelivery><RedeliverySum></RedeliverySum><RedeliveryNum></RedeliveryNum><RedeliveryPayer></RedeliveryPayer><RedeliveryServiceCost>0</RedeliveryServiceCost><AfterpaymentOnGoodsCost></AfterpaymentOnGoodsCost><ServiceType>WarehouseWarehouse</ServiceType><WarehouseRecipientRef>8431c126-f1e6-11e1-a58d-d4ae527baec9</WarehouseRecipientRef><WarehouseRecipientInternetAddressRef>404982f6-e1c2-11e3-8c4a-0050568002cf</WarehouseRecipientInternetAddressRef><UndeliveryReasonsSubtypeDescription></UndeliveryReasonsSubtypeDescription><WarehouseRecipientNumber>1</WarehouseRecipientNumber><LastCreatedOnTheBasisNumber>102-00000089947718</LastCreatedOnTheBasisNumber><LastCreatedOnTheBasisDocumentType>RedeliveryGM</LastCreatedOnTheBasisDocumentType><LastCreatedOnTheBasisPayerType></LastCreatedOnTheBasisPayerType><LastCreatedOnTheBasisDateTime>2018-10-26 14:00:31</LastCreatedOnTheBasisDateTime><LastTransactionStatusGM>Видача</LastTransactionStatusGM><LastTransactionDateTimeGM></LastTransactionDateTimeGM><DateScan>0001-01-01 00:00:00</DateScan><MarketplacePartnerToken></MarketplacePartnerToken><ClientBarcode></ClientBarcode><SenderAddress></SenderAddress><RecipientAddress></RecipientAddress><CounterpartySenderDescription></CounterpartySenderDescription><CounterpartyRecipientDescription></CounterpartyRecipientDescription><CounterpartySenderType>Organization</CounterpartySenderType><PaymentStatus></PaymentStatus><PaymentStatusDate></PaymentStatusDate><AmountToPay></AmountToPay><AmountPaid></AmountPaid><LastAmountTransferGM>0.00</LastAmountTransferGM><LastAmountReceivedCommissionGM>0.00</LastAmountReceivedCommissionGM><AnnouncedPrice></AnnouncedPrice><InternationalDeliveryType></InternationalDeliveryType><Status>Відправлення отримано. Грошовий переказ видано одержувачу.</Status><StatusCode>11</StatusCode><RefEW>42a8b1e9-d5fd-11e8-aa3a-0025b501a04b</RefEW><RedeliveryPaymentCardRef></RedeliveryPaymentCardRef><RedeliveryPaymentCardDescription></RedeliveryPaymentCardDescription><CreatedOnTheBasis></CreatedOnTheBasis><DatePayedKeeping></DatePayedKeeping></item></data><errors/><warnings><item><ID_59000372690877>Please enter a valid phone number from the express invoice to show full information</ID_59000372690877></item></warnings><info/><messageCodes/><errorCodes/><warningCodes/><infoCodes/></root>


Мой php как я отправляю xml запрос и получаю обратно .

$xml = '<?xml version="1.0" encoding="UTF-8"?>
<root>
   <apiKey>МОЙ КЛЮЧ</apiKey>
   <calledMethod>getStatusDocuments</calledMethod>
   <methodProperties>
      <Documents>
         <item>
            <DocumentNumber>'.$value.'</DocumentNumber>
         </item>
      </Documents>
   </methodProperties>
   <modelName>TrackingDocument</modelName>
</root>'
; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://api.novaposhta.ua/v2.0/xml/"); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$body = curl_exec($ch); 
curl_close($ch); 


 echo $body;

Мне нужно данный xml , преобразить в человечкий вид . И из всего хml вывесити в браузер пару строк в таблицу .
5bd99730a01db747266226.png5bd997396478f899383917.png
Чтобы я получил в таблице декларцию и статус и на этом все .
  • Вопрос задан
  • 290 просмотров
Пригласить эксперта
Ответы на вопрос 1
alex-1917
@alex-1917
Если ответ помог, отметь решением
spoiler
<?php



$xml = '<?xml version="1.0" encoding="UTF-8"?>
<root>
   <apiKey>МОЙ КЛЮЧ</apiKey>
   <calledMethod>getStatusDocuments</calledMethod>
   <methodProperties>
      <Documents>
         <item>
            <DocumentNumber>'.$value.'</DocumentNumber>
         </item>
      </Documents>
   </methodProperties>
   <modelName>TrackingDocument</modelName>
</root>'
; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://api.novaposhta.ua/v2.0/xml/"); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$body = curl_exec($ch); 
curl_close($ch); 

$arrXml = gzuncompress($body);
$body ='';
curl_close($curl);
$XmlPos = mb_strpos($arrXml,'<?xml');
$XmlParse = (array)simpleXML_load_string(mb_substr($arrXml, $XmlPos),'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
$arrXml = '';
$json = @json_encode($XmlParse);
$XmlParse = '';
$json = @json_decode($json,1);
$arSuper = array();

$number = '';
$status = '';

	foreach($json["data"] as $item){
		$number = $item->Number;
		$status = $item->Status;
		$arSuper[] = array(
			'number' => (string)$item['Number']['@attributes'],
			'status' => (string)$item['Status']['@attributes'],
		);
	}

$json = '';
echo $number;
echo $status;

print_r($arSuper);
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы