Results 1 to 5 of 5

Thread: Xml compare using QDomElement

  1. #1
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Xml compare using QDomElement

    Hi all,
    I need to compare two xml files.So far i tried using QDomDocument and QDomNode:perator() == 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

    Qt Code:
    1. <Book class="B1" name="ABC">
    2. <property name="Price">
    3. <int>85</int>
    4. </property>
    5. <property name="author">
    6. <string>Hypo</string>
    7. </property>
    8. </widget>
    To copy to clipboard, switch view to plain text mode 

    File2.xml

    Qt Code:
    1. <Book class="B1" name="ABC">
    2. <property name="Price">
    3. <int>85</int>
    4. </property>
    5. <property name="author">
    6. <string>Hypo</string>
    7. </property>
    8. </widget>
    To copy to clipboard, switch view to plain text mode 
    Can anyone guide me on this.How can i proceed?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Xml compare using QDomElement

    Thanks for your reply but what happens if my child nodes are in different order for Example:-

    File1.xml
    Qt Code:
    1. <Book class="B1" name="ABC">
    2. <property name="Price">
    3. <int>85</int>
    4. </property>
    5. <property name="author">
    6. <string>Hypo</string>
    7. </property>
    8. </widget>
    To copy to clipboard, switch view to plain text mode 

    File2.xml

    Qt Code:
    1. <Book class="B1" name="ABC">
    2. <property name="author">
    3. <string>Hypo</string>
    4. </property>
    5. <property name="Price">
    6. <int>85</int>
    7. </property>
    8. </widget>
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  5. #5
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Xml compare using QDomElement

    @adoka
    Thanks that will be the ideal choice.

Similar Threads

  1. QDomElement text
    By emrares in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2010, 09:44
  2. QGraphicsSvgItem from QDomElement
    By casperbear in forum Newbie
    Replies: 0
    Last Post: 9th September 2010, 05:25
  3. QDomElement::elementsByTagName()
    By manojmka in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2008, 12:43
  4. QDomElement
    By sabeesh in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2007, 13:55
  5. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 18:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.