我想用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”并将其解析为新变量?
答案 0 :(得分:3)
不,您已经在父起点,无需添加->sparql
:
$result = new SimpleXMLElement($curl_response);
$boolean = $result->boolean;
echo $boolean;