Results 1 to 10 of 10

Thread: Problems reading XML with QDomDocument

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems reading XML with QDomDocument

    I wrote this in a browser, but I'm sure that this code works fine.
    Qt Code:
    1. QFile file("phones.xml");
    2. if (!file.open(QIODevice::ReadOnly))
    3. return;
    4. if (!doc.setContent(&file)) {
    5. file.close();
    6. return;
    7. }
    8. file.close();
    9.  
    10. QDomElement docElem = doc.documentElement();
    11.  
    12. QDomNode n = docElem.firstChild();
    13. while(!n.isNull()) {
    14. QDomElement e = n.toElement();
    15. if(!e.isNull()) {
    16. if (e.tagName() == "phone") {
    17. qDebug() << "location" << e.attribute("location");
    18. qDebug() << "value" << e.attribute("value");
    19. } else if (e.tagName() == "settings") {
    20. qDebug() << "AfterHourOffset" << e.attribute("AfterHourOffset");
    21. qDebug() << "NumPerButton" << e.attribute("NumPerButton");
    22. qDebug() << "MaxNumToDial" << e.attribute("MaxNumToDial");
    23. }
    24. }
    25. n = n.nextSibling();
    26. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  2. The following user says thank you to spirit for this useful post:

    grantbj74 (27th August 2009)

Similar Threads

  1. Mac OSX OpenGL problems
    By tksharpless in forum Qt Programming
    Replies: 0
    Last Post: 23rd March 2009, 17:27
  2. QDomDocument inside other QDomDocument
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2008, 15:27
  3. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  4. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  5. Adding whitespace in QDomDocument
    By jakamph in forum Newbie
    Replies: 4
    Last Post: 6th February 2006, 22:06

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
  •  
Qt is a trademark of The Qt Company.