如何使用 qt 删除嵌套的 xml 元素
How to delete nested xml element using qt
我有这样的XML文件
<root>
<element>
<child id = "0"> Some Text </child> <-- Target To Delete
</element>
<element>
<child id = "1"> Some Text </child>
</element>
</root>
如何使用Qt库删除ID "0"的子元素。
QDomDocument doc;
doc.setContent(oldXml);
QDomNodeList nodes = doc.elementsByTagName("element");
for (int i = 0; i < nodes.count(); ++i)
{
QDomNode node = nodes.at(i);
QDomElement child = node.firstChildElement("child");
if (!child.isNull() && child.attribute("id") == "0")
{
node.removeChild(child);
}
}
QString newXml = doc.toString();
相关文章:
- 使用 libxml2 解析 XML 文件时缺少元素值
- 使用提升属性树检查 xml 文件中是否存在元素
- 使用 qt c++ 检查 Xml 中是否存在根元素
- 使用 TinyXML 解析 XML 元素 - 无限循环
- 如何使用libxml2从C 中的XML文件中检索节点和特定元素字符串而不使用XPATH
- 如何使用XPath使用libxml2从C 中的XML文件中检索节点和特定元素字符串
- 正在更新微小Xml元素中的数据
- 忽略GSOAP中的未知XML元素节点
- 将xml字符串嵌套到xml元素中的语法
- PugiConvert xml元素内容到C++数组
- 有人可以解释为什么我的XML解析器跳过这些HTML元素的原因
- 如何使用 qt 删除嵌套的 xml 元素
- CodeSynthesis XSD CXX 不解析 XML 文件,表示未声明属性/元素
- 使用 cpp 在 opencv 中的 xml 文件中追加元素
- Qt XML读取元素,并且只获取根
- Qt更新单个XML元素
- 忽略xml元素中的字符
- 使用TinyXML解析XML元素
- 使用TinyXML解析XML元素
- 在c++中解析XML元素