Results 1 to 3 of 3

Thread: Having trouble with direct child nodes using QtXml

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Having trouble with direct child nodes using QtXml

    From the docs :
    QDomNodeList QDomElement::elementsByTagName ( const QString & tagname ) const
    Returns a QDomNodeList containing all descendent elements of this element that are called tagname. The order they are in the node list is the order they are encountered in a preorder traversal of the element tree.
    so the behaviour of elementsByTagName in ur code is justified.

    As for the childNodes(), Are you sure you were on the <Container name="L1Container" autoAdd="true"> tag when you used the childNodes() function ??

    Thirdly... what is iChild in your code ? How are you assigning value to it ??

  2. #2
    Join Date
    Jul 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble with direct child nodes using QtXml

    I see your point about elementsByTagName. Must've glossed over that when I read it earlier. iChild has a comment next to it describing what it is and where it's from, but in fact it was related to a bug I found in my code, so it no longer exists.

    The way I was processing the children of both a <Container> and an <Element> was to get their child nodes (actually in the case of the <Element>, it was the children of <Children>) with childNodes() and parse each in a for loop.

    What I've now done, thanks to an example from a work acquaintance, is grab the firstChildElement() and use something similar to:

    Qt Code:
    1. QDomElement iChild = iParent.firstChildElement();
    2. while (!iChild.isNull())
    3. {
    4. parseFunction(iChild);
    5. iChild = iChild.nextSiblingElement();
    6. }
    To copy to clipboard, switch view to plain text mode 

    Strangly enough, I had used this method before with TinyXML in a school project a while back but it didn't hit me until I saw it in an example. But, it is now working and I'm on to other things.

    Thanks for the reply!

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