Results 1 to 1 of 1

Thread: Qt extract from xml with DOM

  1. #1
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt extract from xml with DOM

    ok, so I have a xml file... smth like this:
    Qt Code:
    1. <?xml version = "1.0" ?>
    2. <!-- My Bookmarks -->
    3. <db>
    4. <user nr="1">
    5. <username>Leoha_Zveri</username>
    6. <password>testpass</password>
    7. </user>
    8. </db>
    To copy to clipboard, switch view to plain text mode 
    in my code i have a function:
    Qt Code:
    1. bool DOMtraverseNode(const QDomNode& domNode) {
    2. QDomNode node = domNode.firstChild();
    3. while( !node.isNull() )
    4. {
    5. if ( node.isElement() )
    6. {
    7. QDomElement element = node.toElement();
    8. qDebug() << "Element: " << element.tagName();
    9. qDebug() << "Element attribute name: " << element.attribute("nr", "not set");
    10.  
    11. }
    12.  
    13. if (node.isText())
    14. {
    15. QDomText text = node.toText();
    16. qDebug() << text.data();
    17. }
    18.  
    19.  
    20. DOMtraverseNode(node);
    21. node = node.nextSibling();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 
    and in main:
    Qt Code:
    1. QFile file("admin.xml");
    2. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    3. {
    4. qDebug("Failed to open file for reading.");
    5. return -1;
    6. }
    7.  
    8. QDomDocument document;
    9. if (!document.setContent(&file))
    10. {
    11. qDebug("Failed to parse the file into a DOM tree.");
    12. file.close();
    13. return -1;
    14. }
    15.  
    16. QDomElement domNode = document.documentElement();
    17. DOMtraverseNode(domNode);
    18.  
    19.  
    20. file.close();
    To copy to clipboard, switch view to plain text mode 
    the question is... how do I check if a 2 QStrings (for example "uname" and "pass" ) entered by the user match, the values from the xml? I can check them separately, returning something from function when it matches the username, and another time when it matches the password,... but what if the xml looks like this:
    Qt Code:
    1. <?xml version = "1.0" ?>
    2. <!-- My Bookmarks -->
    3. <db>
    4. <user nr="1">
    5. <username>Leoha_Zveri</username>
    6. <password>testpass2</password>
    7. </user>
    8. <user nr="2">
    9. <username>Leoha_Zveri2</username>
    10. <password>testpass</password>
    11. </user>
    12. </db>
    To copy to clipboard, switch view to plain text mode 
    ... functions will return that both values are contained in xml, and it will allow to log in, but it's wrong...
    so how can i make this work?
    sorry for my bad english...
    please someone help
    Last edited by Leoha_Zveri; 4th October 2009 at 12:19.

Similar Threads

  1. extract data from photos
    By timmu in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2009, 10:38
  2. How to extract all images from a QT3 .ui file
    By kshahar in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2008, 16:27
  3. How to extract and compress a cpio archive file in Qt
    By sarode in forum Qt Programming
    Replies: 13
    Last Post: 5th January 2008, 10:20
  4. qt ready fn to extract ip address from a qstring
    By nass in forum Qt Programming
    Replies: 3
    Last Post: 26th March 2007, 16:27
  5. extract item from QListWidget
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 20:41

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.