douleng0794 2017-09-17 06:43 采纳率: 0%
浏览 47
已采纳

如何访问XML响应

Good day, I want to access the XML response and echo it to display its value but I don't know how to do it. I already tried some few answers in StackOverflow but I fail.

This is my code.

<?php
error_reporting(E_ALL);
require_once 'ruFunctions.php';

$rentalsUnited = new rentalsUnited();

$ru= $rentalsUnited->getOwners();

if($ru != null){
   $data= simplexml_load_string($ru);
   var_dump($data); // it will return boof(false)
   var_dump($ru);
   echo $data->Pull_ListAllOwners_RS->Status['ID']; //Trying to get property of non-object
}
?>

Results for var_dump($ru);

object(SimpleXMLElement)#2 (3) {
  ["Status"]=>
  string(7) "Success"
  ["ResponseID"]=>
  string(32) "44065d9888304e8cba912bce4d131ab1"
  ["Owners"]=>
  object(SimpleXMLElement)#3 (1) {
    ["Owner"]=>
    object(SimpleXMLElement)#4 (7) {
      ["@attributes"]=>
      array(1) {
        ["OwnerID"]=>
        string(6) "429335"
      }
      ["FirstName"]=>
      string(5) "Test"
      ["SurName"]=>
      string(7) "Tester"
      ["CompanyName"]=>
      string(15) "Test Helpers"
      ["Email"]=>
      string(23) "info@Test.com"
      ["Phone"]=>
      string(12) "+13474707707"
      ["UserAccountId"]=>
      string(3) "602"
    }
  }
}
  • 写回答

1条回答 默认 最新

  • doudao1950 2017-09-17 06:56
    关注

    It looks like $ru is already a SimpleXMLElement, so trying to call simplexml_load_string will fail on this.

    You can see some of the details by

    if($ru != null){
       echo $ru->Status;
    }
    

    You can (probably) list the owners by...

    if($ru != null){
       foreach ($ru->Owners->Owner as $owner ) {
         echo "ownerId=".$owner['OwnerID'].PHP_EOL;
         echo "FirstName=".$owner->FirstName.PHP_EOL;
       }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测