开发者

compare and add elements from one xml to another

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜