-1

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?

anand
  • 11,071
  • 28
  • 101
  • 159

1 Answers1

0

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.

Community
  • 1
  • 1
J. Chomel
  • 8,193
  • 15
  • 41
  • 69