删除 XML 文件中的子节点C++
Removing child node in a XML file C++
我正在使用PugiXml库进行XML相关操作。
我的 XML 文件:
<CurrentStatus>
<Time Stamp= "12:30">
<price>100</price>
<amount>1</amount>
</Time>
<Time Stamp= "14:50">
<price>10</price>
<amount>5</amount>
</Time>
<Time Stamp= "16:30">
<price>10</price>
<amount>5</amount>
</Time>
</CurrentStatus>
出于测试目的,我给出了一个硬编码值,我想删除带有属性Stamp = 14:50
Time
节点。
XML节点删除代码:我使用这个SO问题作为参考来删除节点(名称=Time
和属性=14:50
(。
for (xml_node child = doc.child("CurrentStatus").first_child(); child; )
{
xml_node next = child.next_sibling();
string attributeValue = child.attribute("Stamp").as_string();
if (attributeValue == "14:50")
{
cout << "delete" << endl;
child.parent().remove_child(child);
}
child = next;
}
问:上面的代码运行没有任何错误。它甚至进入if-statement
但为什么原始XML文件在执行后保持不变?
PS:我确定根节点和XML文档通常可以正确读取,因为我能够在控制台上显示XML结构。
我认为问题出在保存上。
我在if-condition
后执行了以下保存语句,它起作用了。
doc.save_file("D:/myfile.xml");
相关文章:
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 删除 XML 文件中的子节点C++
- 检查两个节点在子节点上是否具有相同状态的更优雅的方法
- 语言分析的二叉树实现 - 子节点:不起作用
- Node中的子节点列表在C++中的BFS遍历过程中丢失
- c++ 无法从 XML 获取所有子节点
- 使用访问者设计模式在N- ARY树中重复访问子节点值
- TinyXML2 从节点和所有子节点获取文本
- 遍历仅引用每个节点的子节点的树
- 从父节点中删除子节点 - PugiXML
- 根据其子节点的余额计算 AVL 树节点余额
- 有没有一种方便的方法可以从属性树中删除节点,同时保留其子节点
- 访问BST子节点时出现分段故障.为什么?
- 使用节点指针数组来指向节点的子节点
- 如何使链表具有子节点
- 如何获取所有子节点值
- 解析 AST 中的节点及其自己的(无限数量的嵌套)子节点
- 无法从具有 MSXML 的子节点获取值 C++
- QTreeView 使用示例 - 如何将子节点添加到现有项目
- 如何使用OpenCV库访问xml文件中的子节点