English 中文(简体)
从 PHP 中回声 XML 响应中解析数据
原标题:Parsing data from echoed XML Response in PHP

我正在研究一个网络服务整合项目。 现在, 使用 CURL 方法通过请求并获得 XML 响应。 我并没有保存 XML 响应文件, 而是在我的页面中重复了 XML 响应( 认为这将节省服务器响应时间 ) 。 现在我正在我的页面中收到 XML 响应, 这样的反应,

<?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>

为了将 XML 中的数据保存到我的数据库/ 表 I 需要从节点中解析数据。 我手上有从保存的文件解析 XML 的代码, 但无法在回声 XML 响应中找到相同答案 。 我如何从回声 XML 响应中读取数据 。

需要帮助 提前谢谢

最佳回答

要与 XML 合作, 请使用 < a href=" "http://ru.php.net/ manual/en/book.dom.php" rel = "nofollow" > DOM PHP 类。 它很容易理解,非常有力。

只需以下列方式装入您的响应 XML :

$dom = new DOMDocument;

$dom->loadXML($responsestring);

然后,你可以做任何你想做的 通过DOMDocument的方法操控DOM。

问题回答

您可能需要在 < a href=> 上读取 http://www.php. net/ manual/ en/ suprexml.examples- basic.php" rel = "nofollow" > SproXML , 使您将 xml 文档转换为对象, 使其更容易阅读和操作 。

$xml_object = 新的简单XMLE元素($xmlstr);





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签