【发布时间】:2018-11-23 01:37:40
【问题描述】:
到目前为止,我可以删除我要删除的实际节点的所有子节点,但不能删除节点本身。
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("config/config.xml");
pugi::xpath_query query_network_last_run("//state[network/network_last_run='2']");
pugi::xpath_node_set network_last_run = query_network_last_run.evaluate_node_set(doc);
下面的部分删除了特定部分——但我想删除 network 基于子值 (network_last_run),而不是它的这个子值。
network_last_run[0].node().remove_child("network_gateway");
XML 文件结构
<root>
<state>
<network>
<network_last_run>2<network_last_run>
<network_gateway>192.168.3.1</network_gateway>
</network>
</state>
</root>
我尝试使用后退一步
network_last_run[0].node().parent().remove_child("network");
但似乎只修改了存储在内存中的实际结构(删除了第一个),而不是查询的结构。
我可能会在 for 循环中执行此操作并使用 if 条件来检查子节点值是否匹配,但如果可能的话我想通过查询来执行此操作?
【问题讨论】:
标签: c++ xml xml-parsing pugixml