如何解析来自wolfram alpha的返回数据

时间:2012-10-17 23:45:58

标签: php xml wolframalpha

  

可能重复:
  Extracting HTML from an XML file using simpleXML

我正在尝试将Wolfram Alpha API应用到我的项目中,我真的陷入了这个问题。

他们服务器的返回数据是xml,但我不知道如何在浏览器中显示数据。

我想使用php在<img>标记下显示标记和<subpod>标记,但不知道如何执行此操作。

任何人都可以帮我解决这个问题吗?非常感谢!

<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='true'
    error='false'
    numpods='4'
    datatypes='Word'
    timedout='Data,Character'
    timedoutpods=''
    timing='1.566'
    parsetiming='0.116'
    parsetimedout='false'
    recalculate='http://www4b.wolframalpha.com/api/v2/recalc.jsp?id=MSPa17571a3db4591h53ha1200000d7e8c604egche19&amp;s=10'
    id='MSPa17581a3db4591h53ha1200005hcfi072h5329b57'
    host='http://www4b.wolframalpha.com'
    server='10'
    related='http://www4b.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa17591a3db4591h53ha12000065e4habf2bag446e&amp;s=10'
    version='2.6'>
 <pod title='Input interpretation'
     scanner='Identity'
     id='Input'
     position='100'
     error='false'
     numsubpods='1'>
  <markup><![CDATA[<div id="pod_0100" class="pod "><hr class="top" /><h2>
      Input interpretation<span class="colon">:</span></h2><ul class="h"></ul><div id="subpod_0100_1" class="sub "><div class="output pnt" id="scannerresult_0100_1"><img height="18"width="163" src="http://www4b.wolframalpha.com/Calculate/MSP/MSP17631a3db4591h53ha1200001i123763cde8fada?MSPStoreType=image/gif&s=10&amp;w=163&amp;h=18" id="i_0100_1" alt="common  (English word)" title="common  (English word)"  data-attribution="" /></div><div class="annotpod">
    </div></div>
<hr class="bot" /></div>]]></markup>
  <subpod title=''>
   <img src='http://www4b.wolframalpha.com/Calculate/MSP/MSP17641a3db4591h53ha1200004eg12d5dbfca04h8?MSPStoreType=image/gif&amp;s=10'
       alt='common  (English word)'
       title='common  (English word)'
       width='163'
       height='18' />
  </subpod>
 </pod>


......more

1 个答案:

答案 0 :(得分:0)

这很容易

$xml = new SimpleXMLElement($xml);
var_dump($xml->pod->subpod->img);