Results 1 to 4 of 4

Thread: not interpreting the & character

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question not interpreting the & character

    I write an xml file and i insert a text node using this function
    Qt Code:
    1. QDomDocument::createTextNode ( const QString & value );
    To copy to clipboard, switch view to plain text mode 

    I have the necessity to insert the '&' character into the "value" object....
    but when i look for the created xml file, it inserts '&' instead of the single '&'.
    Any idea??
    Last edited by dreamer; 14th June 2008 at 00:22.

  2. #2
    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: not interpreting the & character

    This is correct. Ampersand is a special character in xml and has to be encoded into an entity. When you read it back it will become "&" again.

  3. #3
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: not interpreting the & character

    the problem is that i then read the text directly from the xml file using a QTextStream and the readLine() function, so the '&' isn't converted to '&'.

    how i could obtain my behaviour?
    I have an xml file with some QDomElement and each of them has one child that is a QDomText node.
    How can i iterate between the TextNode and print theirs contents?????

  4. #4
    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: not interpreting the & character

    Quote Originally Posted by dreamer View Post
    the problem is that i then read the text directly from the xml file using a QTextStream and the readLine() function, so the '&' isn't converted to '&'.

    how i could obtain my behaviour?
    1. Don't read using QTextStream or...
    2. Don't write using QDomDocument or...
    3. Replace all occurences of & with pure ampersands.

    How can i iterate between the TextNode and print theirs contents?????
    Qt Code:
    1. for(QDomElement elem = someOther.firstChildElement(); !elem.isNull(); elem = elem.nextSiblingElement())
    2. qDebug() << elem.text();
    To copy to clipboard, switch view to plain text mode 

    Or use DomElementContainer which is available on my blog.

Similar Threads

  1. printer the chinese character with QPrinter
    By trytoremeber963 in forum Qt Programming
    Replies: 0
    Last Post: 3rd June 2008, 08:42
  2. how to get last character of QLineEdit
    By yagabey in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2008, 16:38
  3. Character from argument disappears
    By Pepe in forum Qt Programming
    Replies: 13
    Last Post: 19th June 2007, 23:48
  4. Determine if a font can display a character
    By jrideout in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2006, 10:33
  5. Unicode Character Problem
    By prakash in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2006, 07: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.