0

我正在尝试从 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(); 
4

1 回答 1

-1
$web_config = new SimpleXMLElement('web.config',null,true);
$map_node = $web_config->xpath( sprintf('//rewrite/rewriteMaps/rewriteMap[@name="%s"/add[@value="%d"]', 'myMap', 1) );

if (!empty($map_node)) {
    unset($map_node[0][0]);
}

$web_config->asXml() 
于 2011-02-03T05:59:10.237 回答