QDomDocument.setContent -> .toString Double quotes change to single quotes
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
Re: QDomDocument.setContent -> .toString Double quotes change to single quotes
Re: QDomDocument.setContent -> .toString Double quotes change to single quotes
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?
Re: QDomDocument.setContent -> .toString Double quotes change to single quotes
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.
Re: QDomDocument.setContent -> .toString Double quotes change to single quotes
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.
Re: QDomDocument.setContent -> .toString Double quotes change to single quotes
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
Re: QDomDocument.setContent -> .toString Double quotes change to single quotes
Or you just change the returned string, the processing instruction is the first use of quotes, right?
Cheers,
_
Re: QDomDocument.setContent -> .toString Double quotes change to single quotes
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.