使用 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
我迭代以查看所需名称的框架是否存在,如果存在,我想完全重写它。如果没有,我想将其添加到根元素的底部。
有人有这方面的例子吗?
谢谢
Right now, I save my data by simply rewriting the file requested by the user. The way my xml is structured is like this:
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
I iterate through to see if the skeleton of desired name exists and if it does I want to completely rewrite it. If not, I want to add it to the bottom of the root element.
Does anyone have an example of this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,这只是一个拆分步骤的问题。
首先,定义一个
TiXmlElement *
并将其设置为 0。迭代Skeletons
的所有子元素。如果您找到正确的Skeleton
,请将您的TiXmlElement *
指向它。其次,如果您还没有找到它(
TiXmlElement *
仍然是 0),请创建一个新的 Skeleton 并将您的TiXmlElement *
指向它。最后,在该
TiXmlElement *
下创建一个新骨骼。Basically, this is just a matter of splitting the steps.
First, define a
TiXmlElement *
and set it to 0. Iterate over all children ofSkeletons
. If you find the correctSkeleton
, point yourTiXmlElement *
to it.Secondly, if you haven't found it (
TiXmlElement *
still 0), create a new Skeleton and point yourTiXmlElement *
to it.Finally, create a new bone underneath that
TiXmlElement *
.