Results 1 to 7 of 7

Thread: How to get Text value of a QDomElement ? (noob question)

  1. #1
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Wink How to get Text value of a QDomElement ? (noob question)

    Hi,
    say I have QDomElement containing :

    Qt Code:
    1. <text:p>
    2. etc etc etc etc,
    3. <text:s/>
    4. blablabla bla bla bla bla bla
    5. </text:p>
    To copy to clipboard, switch view to plain text mode 

    How do i get the string "etc etc etc etc, <text:s/> blablabla bla bla bla bla bla" ?
    I tried .totext().data() but it doesnt appear to work.

    What is the proper course of action ?

  2. #2
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get Text value of a QDomElement ? (noob question)

    Well, so i made a function to parse element, wish there was an more handy way, but such is life.

  3. #3
    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: How to get Text value of a QDomElement ? (noob question)

    The above code is not valid.
    You cannot have <> as text. You will need to use CDATA..

  4. #4
    Join Date
    Mar 2010
    Location
    Capelle aan den IJssel, Netherlands
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: How to get Text value of a QDomElement ? (noob question)

    If you browse through a QDomElement, you can use ::tagName() to get the name between < and >.
    If you need the value of the tag, so the text between <tag> your text here </tag>, you can just use the ::text() method of QDomElement.

    As easy as that

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get Text value of a QDomElement ? (noob question)

    Iterate over all child nodes, use QDomNode::save() to save each of them to a string. Then concatenate all strings you received and you're done. Or don't use DOM but rather some smarter approach
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get Text value of a QDomElement ? (noob question)

    Thanks all for replying,

    Wysota, i am curious as to what you mean by smarter approach . And thanks for suggesting ::save(), i wasnt aware of it, this is primarily why i asked here on the forum, in hope of someone suggesting some functions i wasnt aware of. Qt is big! But it doesnt feel bloated at all (to me).

    have a nice day

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get Text value of a QDomElement ? (noob question)

    Quote Originally Posted by BillGates View Post
    Wysota, i am curious as to what you mean by smarter approach
    QXmlStreamReader
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. (noob question) write qint64 into qsharedmemory
    By daemonna in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2010, 11:28
  2. Setting the text in QDomElement
    By dpatel in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2010, 13:12
  3. QWizard noob question
    By Ossi in forum Newbie
    Replies: 5
    Last Post: 2nd September 2009, 12:30
  4. QDomElement::text() returns corrupted strings
    By sladecek in forum Qt Programming
    Replies: 6
    Last Post: 7th March 2009, 14:07
  5. a simple noob question
    By wrproject in forum Newbie
    Replies: 1
    Last Post: 1st July 2008, 23:25

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.