从 simpleXML 中删除节点
我正在尝试从 web.config 文件中取消设置节点,但它似乎不起作用。有人知道我做错了什么吗?如果有更好的方法请告诉我?
$web_config = simplexml_load_file('web.config');
$nodes = $web_config->children();
$att_name = 'myMap';
$value = '1';
$map_node = $nodes[0]->xpath( sprintf('rewrite/rewriteMaps/rewriteMap[@name="%s"]/add[@value="%d"]', $att_name, $value) );
print_r($map_node); // this outpus the correct node
if (!empty($map_node)) {
unset($map_node)
} else {
printf('No maps with value: "%d" found', $value);
}
$web_config->asXML();
I'm trying to unset a node from a web.config file but it doesn't seem to be working. Anyone know what I'm doing wrong? If there's a better approche please let me know?
$web_config = simplexml_load_file('web.config');
$nodes = $web_config->children();
$att_name = 'myMap';
$value = '1';
$map_node = $nodes[0]->xpath( sprintf('rewrite/rewriteMaps/rewriteMap[@name="%s"]/add[@value="%d"]', $att_name, $value) );
print_r($map_node); // this outpus the correct node
if (!empty($map_node)) {
unset($map_node)
} else {
printf('No maps with value: "%d" found', $value);
}
$web_config->asXML();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)