PDA

View Full Version : not interpreting the & character



dreamer
13th June 2008, 23:47
I write an xml file and i insert a text node using this function


QDomDocument::createTextNode ( const QString & value );


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??

wysota
14th June 2008, 07:08
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.

dreamer
14th June 2008, 08:31
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?????

wysota
14th June 2008, 09:00
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?????


for(QDomElement elem = someOther.firstChildElement(); !elem.isNull(); elem = elem.nextSiblingElement())
qDebug() << elem.text();

Or use DomElementContainer which is available on my blog.