Results 1 to 3 of 3

Thread: QDomElement text

  1. #1
    Join Date
    Aug 2009
    Posts
    33
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QDomElement text

    How can i get the text of a single DomElement?

    In the documentation it says " the text() function operates recursively to find the text (since not all elements contain text)."

    So if i have something like this

    <faktoren>
    <faktor resolution="1680x1050" fullscreen="5">6</faktor>
    <faktor resolution="1280x1024" fullscreen="5">8</faktor>
    </faktoren>

    and i call the text function on the faktoren tag i get "68" and i should get an empty string.

    So my question is how can i get the text value of a single element, and ignore it's child tags?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QDomElement text

    No you get "68" since it works recursive... If you want get "8" call text() on the tag faktor. Or look if a tag has QTextNode as a child.

  3. #3
    Join Date
    Aug 2009
    Posts
    33
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs down Re: QDomElement text

    Problem solved. Thanks Lykurg for your advice.

    Qt Code:
    1. QDomNodeList nodeList = elem.childNodes();
    2.  
    3.  
    4. for ( int i = 0; i < nodeList.size(); i++ )
    5. {
    6. QDomElement nodeElement = nodeList.item(i).toElement();
    7. QDomText txtNode = nodeList.item(i).toText();
    8. QString str = txtNode.data();
    9. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsSvgItem from QDomElement
    By casperbear in forum Newbie
    Replies: 0
    Last Post: 9th September 2010, 04:25
  2. How to get Text value of a QDomElement ? (noob question)
    By BillGates in forum Qt Programming
    Replies: 6
    Last Post: 31st August 2010, 14:01
  3. Setting the text in QDomElement
    By dpatel in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2010, 13:12
  4. QDomElement::text() returns corrupted strings
    By sladecek in forum Qt Programming
    Replies: 6
    Last Post: 7th March 2009, 14:07
  5. QDomElement
    By sabeesh in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2007, 12: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.