【发布时间】:2010-08-22 13:35:42
【问题描述】:
我正在尝试通过 API 发出调用,以便删除用户属性。当我转到ourwiki.com/@api/users/=john_smith%40ourwiki.com/properties 时,它会返回包含所有用户属性的 XML。
我正在尝试将该 XML 存储在变量 $xmlString 中,然后我应该能够循环获取属性并依次删除。用户属性是键值,其中键和值可以是任何值,因此遗憾的是无法知道所有选项。
到目前为止的代码:
$delete = "http://www.ourwiki.com/@api/DELETE:users/$user_id/properties/%s";
$xmlString = file_get_contents('ourwiki.com/@api/users/=john_smith%40ourwiki.com/properties')
$xml = new SimpleXMLElement($xmlString);
foreach($xml->property as $property) {
$name = $property['name']; // the name is stored in the attribute
file_get_contents(sprintf($delete, $name));
}
由于某种原因,file_get_contents 似乎无法获取 XML。我什至确保在环境中启用了 allow_url_fopen 。对此的任何帮助将不胜感激。
【问题讨论】:
-
您是否收到错误/警告消息并将 error_reporting 设置为 E_ALL? $xmlString (
var_dump($xmlString);) 的值是多少? -
假设我只是在分配变量后添加 var_dump($xmlString),它返回 bool(false)。