【发布时间】:2014-04-21 08:57:53
【问题描述】:
目前我正在使用 unset() 删除 simpleXML 中的父节点,并将其写回 XML 文件
我试了这段代码,前段时间还可以用,清理完代码后我找不到为什么突然不能用了,
我采取的调试方法:文件可以访问,我可以进入循环和if语句,文件被保存(notepad++要求我重新加载),但<systemInfo></systemInfo>没有被删除
这是我的示例代码:
$userorig = $_POST['user'];
$userinfos = simplexml_load_file('userInfo.xml'); // Opens the user XML file
foreach ($userinfos->userinfo->account as $account)
{
// Checks if the user in this iteration of the loop is the same as $userorig (the user i want to find)
if($account->user == $userorig)
{
echo "hello";
$rootSystem = $account->systemInfo;
unset($rootSystem);
}
}
$userinfos->saveXML('userInfo.xml');
我的 XML 文件:
<userinfos>
<userinfo>
<account>
<user>TIGERBOY-PC</user>
<toDump>2014-03-15 03:20:44</toDump>
<toDumpDone>0</toDumpDone>
<initialCheck>0</initialCheck>
<lastChecked>2014-03-16 07:12:17</lastChecked>
<alert>1</alert>
<systemInfo>
... (many nodes and sub nodes here) ...
</systemInfo>
</account>
</userinfo>
</userinfos>
【问题讨论】:
标签: php xml debugging simplexml unset