c++ - 使用 TinyXML 修改文档

标签 c++ xml tinyxml

现在,我通过简单地重写用户请求的文件来保存我的数据。我的 xml 的结构方式是这样的:

Skeleons root
    Skeleton with string name attribute
       bone with attributes
       bone with attributes
       bone with attributes
       bone with attributes
    end Skeleton
   Skeleton with string name attribute
       bone with attributes
       bone with attributes
       bone with attributes
       bone with attributes
    end Skeleton
    ....
   end Skeletons root

我遍历以查看所需名称的框架是否存在,如果存在我想完全重写它。如果没有,我想将它添加到根元素的底部。

有没有人有这方面的例子?

谢谢

最佳答案

基本上,这只是拆分步骤的问题。

首先,定义一个 TiXmlElement * 并将其设置为 0。遍历 Skeletons 的所有子项。如果找到正确的 Skeleton,请将 TiXmlElement * 指向它。

其次,如果您还没有找到它(TiXmlElement * 仍然是 0),请创建一个新的骨架并将您的 TiXmlElement * 指向它。

最后,在 TiXmlElement * 下创建一个新骨骼。

关于c++ - 使用 TinyXML 修改文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7108349/

相关文章:

c++ - 使用委托(delegate)构造函数时的成员初始化

C++ 不明确重载

c++ - Qt:将事件发布到 QThread 的正确方法?

java - 在 Spring Security Oauth2 中使用 RemoteTokenServices 配置资源服务器

java - 从java中的xml响应中检索值

c++ - 使用 TinyXML 在 XML 文档中查找特定节点

c++ - 对于 C++,是否有两次从控制台中的 txt 文件重定向(cin)输入?

python - 如何从 sitemap.xml 文件创建列表以在 python 中提取 url?

C++ 段错误 -tinyXML

c++ - TinyXML 元素提取为文本