Xml compare using QDomElement
Hi all,
I need to compare two xml files.So far i tried using QDomDocument and QDomNode::operator() == but i failed since the book properties can be in any order.All i need to do is compare both file and say they are same or not.For example:-
File1.xml
Code:
<Book class="B1" name="ABC">
<property name="Price">
<int>85</int>
</property>
<property name="author">
<string>Hypo</string>
</property>
</widget>
File2.xml
Code:
<Book class="B1" name="ABC">
<property name="Price">
<int>85</int>
</property>
<property name="author">
<string>Hypo</string>
</property>
</widget>
Can anyone guide me on this.How can i proceed?
Re: Xml compare using QDomElement
You could traverse both DOM tree and on each step you check that the two nodes have the same type.
If the node is an element, compare names and attribute maps.
If the node is a text element, also compare text.
Or read both files into DOM trees and then write them to two temporay files or buffers and then compare their content.
Cheers,
_
Re: Xml compare using QDomElement
Thanks for your reply but what happens if my child nodes are in different order for Example:-
File1.xml
Code:
<Book class="B1" name="ABC">
<property name="Price">
<int>85</int>
</property>
<property name="author">
<string>Hypo</string>
</property>
</widget>
File2.xml
Code:
<Book class="B1" name="ABC">
<property name="author">
<string>Hypo</string>
</property>
<property name="Price">
<int>85</int>
</property>
</widget>
Re: Xml compare using QDomElement
Well, if that can happen, you'll have to load the data into program data structures and compare those.
Cheers,
_
Re: Xml compare using QDomElement
@adoka
Thanks that will be the ideal choice.