I am working on a web-service integration project. Now, pass the request using cURL method and getting an XML response. Instead of saving the XML response file, i echoed the XML response in my page(thought it will save server response time). Now i am getting XML response in my page echoed like this,
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Body>
<CreateShipmentReply xmlns="http://www.parcelforce.net/ws/ship/v5">
<CompletedShipmentInfo>
<Status>ALLOCATED</Status>
<CompletedShipments>
<CompletedShipment>
<ShipmentNumber>MK0030912</ShipmentNumber>
</CompletedShipment>
</CompletedShipments>
<RequestedShipment>
<DepartmentId>1</DepartmentId>
<ShipmentType>DELIVERY</ShipmentType>
<ContractNumber>P664383</ContractNumber>
<ServiceCode>SUP</ServiceCode>
<ShippingDate>2012-05-25</ShippingDate>
<RecipientContact>
<BusinessName>BUSINESS NAME</BusinessName>
In order to save the data in XML into my database/table i need to parse it from the nodes. I am having the code for parsing the XML from a saved file, but couldn’t find a solution for the same in echoed XML response. How can i read the data from an echoed XML response.
Need Help. Thanks in advance.
To work with XML use DOM PHP class. It’s pretty easy to understand and very powerfull.
Just load your response XML by:
Then you can do whatever you want manipulating DOM though DOMDocument methods.