duanhuang4306 2018-02-28 05:18
浏览 60


I am trying to access a single data point from the XML below. My goal would then be to insert into an html table. The following code has been giving me a stdClass Object and I can't figure out how to grab a single data point.

Here is the XML:

<?xml version="1.0" encoding="utf-8"?>
  <data _idtype="ticker" _id="QYLD" _MstarId="F00000QEMN" _CurrencyId="CU$$$$$USD">
    <api _id="z87pq63qh3gbhraf">

And the PHP:

$xml = simplexml_load_file($url); // URL with above XML

$jsonConvert = json_encode($xml);

$singleDataPoint = json_decode($jsonConvert);


  • 写回答

1条回答 默认 最新

  • duanjiong1952 2018-02-28 05:49

    Actually your json functions are not doing anything at all. json_encode is the opposite of json_decode, so you can just completely omit those two lines.

    The contents of the data points can be found, for example:

    $xml = simplexml_load_file($url);

    If you're just echoing the value or using it in a string context, you don't need __toString() since that will be implied, but beware that without this, it is really an instance of an SimpleXMLElement object, not an actual string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥15 利用加权最小二乘法求亚马逊各类商品的价格指标?怎么求?
    • ¥15 c++ word自动化,为什么可用接口是空的?
    • ¥15 Matlab计算100000*100000的矩阵运算问题:
    • ¥50 VB6.0如何识别粘连的不规则的数字图片验证码
    • ¥16 需要完整的这份订单所有的代码,可以加钱
    • ¥30 写一个带界面控制的机房电脑一键开机关机并且实时监控的软件
    • ¥15 Stata数据分析请教
    • ¥15 请教如何为VS2022搭建 Debug|win32的openCV环境?
    • ¥15 关于#c++#的问题:c++如何使用websocketpp实现websocket接口调用,求示例代码和相关资料
    • ¥15 51单片机的外部中断,按下按键后不能切换到另一个模式