比较一个 xml 中的元素并将其添加到另一个 xml
我有两个 xml 文件
XML1
<node>
<name>abc</name>
<age>25</age>
</node>
XML2
<node>
<name>abc</name>
<age>25</age>
</node>
<node>
<name>xyz</name>
<age>27</age>
</node>
我想比较这两个文件并将缺少的节点从 XML2 添加到 XML1。 我在 C++ 中使用tinyxml。
我正在考虑向每个节点添加一个 guid,即
<node id={732C8F52-D3E2-4929-9199-48F8F38EA5D3}>
<name>xyz</name>
<age>27</age>
</node>
现在当我进行比较时,我可以循环遍历 xml 中的节点并根据 id 比较节点并将缺少的节点添加到 XML1 中。
有没有更好的方法来实现这一点?
I have two xml files
XML1
<node>
<name>abc</name>
<age>25</age>
</node>
XML2
<node>
<name>abc</name>
<age>25</age>
</node>
<node>
<name>xyz</name>
<age>27</age>
</node>
I want to compare these two files and add missing nodes from XML2 to XML1.
I am using tinyxml in C++.
I am thinking of adding a guid to each node ie
<node id={732C8F52-D3E2-4929-9199-48F8F38EA5D3}>
<name>xyz</name>
<age>27</age>
</node>
Now when I will compare I can loop through nodes in both xml and compare nodes based on id and add the missing nodes into XML1.
Is there any better way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 XML 解析库当然更好,例如 Property_Tree Boost 存储库中的库,TinyXML 或 pugixml > - 据说非常强大。
您必须能够根据上述提供的功能找到一些比较器(或简单地构建一个比较器)并比较您的记录。
使用 Boost 读取和写入 XML 文件了解更多信息。
It certainly is better to use an XML parsing library, e.g. one given in the Property_Tree library in the Boost Repository, TinyXML or pugixml - which is said to be very powerful.
You must be able to find some comparator (or build one simply) based on the functionalities provided by the above and compare your records.
Using Boost to read and write XML files for more.