PDA

View Full Version : QDomDocument.setContent -> .toString Double quotes change to single quotes



MickLip
20th March 2014, 10:36
Hi to all!

I see a strange behaviour when reading and writing XML-Files to and from an QDomDocument.
What i do is:
I read a given XML-File which starts with <?xml version="1.0" encoding="iso-8859-1"?> using the QDomDocument.setContent(QFile.....
Then i do some modifications in the QDomDocument (not necessary to reproduce the behaviour)
Last i write it out with Stream << QDomDocument.toString(2)

What i see is that the double quotes in the xml-Declaration (<?xml version="1.0" encoding="iso-8859-1"?>) change in single quotes.

Anyone any idea where to look for the error?

Mick

wysota
20th March 2014, 17:25
Why is that an error?

MickLip
21st March 2014, 06:55
That's exactly what i asked myself yesterday ;-)
A customer complained about the single quotes and in every example i found there are double quotes in the xml-declaration.
But you are right. A validation of the xml file with the single qoutes gives no error.
But why does the QDomDocument write such an unusual syntax?

wysota
21st March 2014, 07:14
Probably because it is programmed to work this way ;) Both types of quotes are valid quotes in XML so unless you are working with a broken parser that does not accept sngle quotes, there is no need to worry.

ChrisW67
21st March 2014, 07:39
It would be an error if QDomDocument were changing quotes in element text or CDATA blocks.

I use QXmlStreamWriter quite a bit and it prefers double quotes. Variety is the spice of life.

MickLip
21st March 2014, 08:51
Ok, we all agree now that it's no error :-)
If i can't convince our customer that it's ok how it is, i wil take a look at QXmlStreamWriter.
Thanks for your help!

Mick

anda_skoa
21st March 2014, 09:40
Or you just change the returned string, the processing instruction is the first use of quotes, right?

Cheers,
_

MickLip
21st March 2014, 10:24
Yes, that would be an option. And it's easy to do. If it's the only exception to handle it would be ok.
Alway when i think of those solutions i feel a kind of dislike. But sometimes one has to accept it ;-)
Thanks for the hint.