Results 1 to 4 of 4

Thread: How to escape special character from QXmlStreamWriter?

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to escape special character from QXmlStreamWriter?

    Hi,

    I need to output an xml with <a href="...">

    But QXmlStreamWriter change it to

    &lt;a href=&quot;...&quot;&gt;

    Is there a way to escape those characters?

    Thanks!

    PS. In fact I am using QXmlStreamWriter to generate an html file....

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to escape special character from QXmlStreamWriter?

    Yes, by using QXmlWriter to write the markup for you... Rather than trying to treat it as a dumb stream.
    Qt Code:
    1. QXmlStreamWriter w;
    2. ...
    3. w.writeStartElement("a");
    4. w.writeAtrribute("href", "http://www.qtcentre.org");
    5. w.writeCharacters("Qt Centre");
    6. w.writeEndElement();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to escape special character from QXmlStreamWriter?

    The string is passed in. Do I have to wake through each char in the string?

    This is the pseudo-code, where text contains "<", ">", """...

    Qt Code:
    1. void foo( const QString& text )
    2. {
    3.  
    4. /// writer is somewhere
    5. writer.writeCharacters( text );
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2014
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to escape special character from QXmlStreamWriter?

    Use the contained device object on the xmlwriter object to write the string(text) converting it to a byte array.

    The text is written whithout scaping any characters.

    Qt Code:
    1. w.writeStartElement("Value");
    2. w.writeCharacters("");
    3. w.device()->write(text.toByteArray());
    4. w.writeEndElement();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Qt Xml QDomDocument Special character handling
    By Prady_80 in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2013, 15:47
  2. QString Special Character Problem
    By hakiim35 in forum Qt Programming
    Replies: 1
    Last Post: 3rd October 2011, 14:38
  3. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  4. Special character's HTML entity to string
    By Hiba in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2009, 14:05
  5. Special Character Handling
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 22:58

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.