View Full Version : How to escape special character from QXmlStreamWriter?
lni
25th February 2014, 06:34
Hi,
I need to output an xml with <a href="...">
But QXmlStreamWriter change it to
<a href="...">
Is there a way to escape those characters?
Thanks!
PS. In fact I am using QXmlStreamWriter to generate an html file....
ChrisW67
25th February 2014, 10:01
Yes, by using QXmlWriter to write the markup for you... Rather than trying to treat it as a dumb stream.
QXmlStreamWriter w;
...
w.writeStartElement("a");
w.writeAtrribute("href", "http://www.qtcentre.org");
w.writeCharacters("Qt Centre");
w.writeEndElement();
lni
25th February 2014, 11:53
The string is passed in. Do I have to wake through each char in the string?
This is the pseudo-code, where text contains "<", ">", """...
void foo( const QString& text )
{
/// writer is somewhere
writer.writeCharacters( text );
}
thidalgo
29th September 2014, 11:09
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.
w.writeStartElement("Value");
w.writeCharacters("");
w.device()->write(text.toByteArray());
w.writeEndElement();
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.