解析<boolean> </boolean>之间的字符串

时间:2015-02-26 07:50:19

标签: php xml simplexml

我想用php

从xml解析“true”
<?xml version="1.0"?> 
<sparql xmlns="http://www.w3.org/2005/sparql-results#"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd">

  <head>
    <link href="example2.rq" />
 </head>

  <boolean>true</boolean>

</sparql>

确切的结果是:

  

我尝试使用:

$curl_response = curl_exec($curly);
curl_close($curly);
$result = new SimpleXMLElement($curl_response);
print_r($result);
echo $result->sparql->boolean;

但它不起作用。有没有办法从该xml中获取“true”并将其解析为新变量?

1 个答案:

答案 0 :(得分:3)

不,您已经在父起点,无需添加->sparql

$result = new SimpleXMLElement($curl_response);
$boolean = $result->boolean;
echo $boolean;

Sample Output