Results 1 to 5 of 5

Thread: QDomDocument and reading XML

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomDocument and reading XML

    Hi,

    The tag "Input" is child the node "Node". Is its problem.

    Marcelo E. Geyer

  2. #2
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomDocument and reading XML

    Not able to get the child nodes of "Node" this way:
    Qt Code:
    1. for(signed i(0); i<n.childNodes().count();i++){
    2.  
    3. QDomNode childNode = n.childNodes().item(i);
    4. QDomElement e = childNode.toElement();
    5. QString name = e.tagName();
    6. if(name == "Input") {
    7.  
    8. QString name1 = e.attribute("name","");
    9. QString type1 = e.attribute("type","");
    10. QString value1 = e.attribute("value","");
    11.  
    12. qDebug() << name1 << type1 << value1;
    13. }
    To copy to clipboard, switch view to plain text mode 

    It's because:
    Qt Code:
    1. n.hasChildNodes(); // = 0
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomDocument and reading XML

    I didn't find any solution so far. May be some one point out the solution.

    Cheers

    Prashant

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDomDocument and reading XML

    chage this:
    Qt Code:
    1. QDomNode n = doc.firstChild();
    To copy to clipboard, switch view to plain text mode 
    to this:
    Qt Code:
    1. QDomElement e = doc.documentElement(); // now e contains "Node" - it's a document element - means root element
    To copy to clipboard, switch view to plain text mode 
    and use QDomElements if you want to get only elements. You can iterate through "Node" childs like this:
    Qt Code:
    1. QDomElement child = e.firstChildElement();
    2. while (!child.isNull()) {
    3. // do sth with child
    4. // it should be "Input" in first iteration and "Output" in second one
    5. child = child.nextSiblingElement(); // move 'child' to be the next sibling element
    6. }
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. The following user says thank you to faldzip for this useful post:

    prashant (20th September 2009)

Similar Threads

  1. Problems reading XML with QDomDocument
    By grantbj74 in forum Qt Programming
    Replies: 9
    Last Post: 27th August 2009, 08:14
  2. XML File reading issue
    By yogesh in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2009, 14:46
  3. help in reading XML file
    By cshiva_in in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2008, 13:55

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.