仅获取XML部分

时间:2018-02-28 19:16:14

标签: xml

以下是我在使用CURl向webservice发送请求时获得的API响应。 从下面的Response中,我只需要xml部分,我需要解析它以获得不同的值。

响应:

HTTP/1.1 200 OK
Date: Sat, 20 Dec 2008 10:54:25 GMT
Content-Length: 62
Content-Type: text/plain
Cache-control: private

<?xml version="1.0"?>

-<ns0:REPORT_REQUEST_ROOT xmlns:ns0="http://www.dnvgl.com/Concert_Integration/PreBillingReport" Operation="Generate Report">


-<ns0:REPORT_REQUEST>


-<ns0:INTEGRATION_HEADER>

<ns0:RequestedOperation>Generate Report</ns0:RequestedOperation>

<ns0:ReceiverSystem>CON</ns0:ReceiverSystem>

<ns0:SenderSystem>EBS</ns0:SenderSystem>

<ns0:SentTimeStamp>2018-02-27 14:14:40</ns0:SentTimeStamp>

</ns0:INTEGRATION_HEADER>


-<ns0:ReportInfo>


-<ns0:Report>

<ns0:PV_ORG_ID/>

<ns0:COST_CENTER/>

<ns0:PV_OUT_LINK>test</ns0:PV_OUT_LINK>

<ns0:REQUEST_STATUS>SUCCESS</ns0:REQUEST_STATUS>

<ns0:ERROR_MESSAGE>Refer to the link for the report</ns0:ERROR_MESSAGE>

<ns0:REQUEST_ERROR_DTLS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

<ns0:DRAFT_INVOICE_DATE>2018-02-27T00:00:00.000+01:00</ns0:DRAFT_INVOICE_DATE>


-<ns0:ORDER_LIST>


-<ns0:ORDER_LIST_ITEM>

<ns0:ORDER_NUMBER>223006312</ns0:ORDER_NUMBER>

</ns0:ORDER_LIST_ITEM>

</ns0:ORDER_LIST>

</ns0:Report>

</ns0:ReportInfo>

</ns0:REPORT_REQUEST>

</ns0:REPORT_REQUEST_ROOT>

我需要解析xml来获取ResponseStatus。 我如何获得xml部分以及如何解析它以获得ResponseStatus?

CURL:

$ ch = curl_init($ URL);

                                        curl_setopt($ch, CURLOPT_MUTE, 1);
                                        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                                        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                                        curl_setopt($ch, CURLOPT_POST, 1);
                                        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                                                                   "Content-Type: application/xml", 
                                                                                    "Ocp-Apim-Subscription-Key: $key",
                                                                                    "Authorization: $token1",                       
                                                                                    "Content-length: ".strlen($xml_data),
                                                                                    ));

                                        curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");

                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

                                        curl_setopt($ch, CURLOPT_HEADER, true);

                                        $output = curl_exec($ch);               

1 个答案:

答案 0 :(得分:0)

只需移除CURLOPT_HEADER参数(或将其设置为FALSE),就会明确要求PHP在输出中呈现标题。

检查https://secure.php.net/manual/en/function.curl-setopt.php