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.

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



  • ¥30 电脑误删了手机的照片怎么恢复?
  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
  • ¥20 学生成绩管理系统设计
  • ¥15 来一个cc穿盾脚本开发者
  • ¥15 CST2023安装报错
  • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了