Qt Xml QDomDocument Special character handling
-
Hi,
I have QString which contains XML data that is obtained from a remote system.
The problem with this data is that the special characters are not translated. for example & is not translated to &.
When I try to parse this xml using QDomDocument's setContent method, I experience a failure.Does Qt Xml handling any how have the facility of escaping such characters or replacing them with the translated characters so that the Xml document becomes a valid document?
Any help is greatly appreciated.
Please note that I cannot change the data format that I am receiving as the remote system is not under my control, so CDATA option is not available.
Thanks
-
[quote author="prady_80" date="1383747289"]
I have QString which contains XML data that is obtained from a remote system.
The problem with this data is that the special characters are not translated. for example & is not translated to &.[/quote]
As you may have noticed translating "&" to "&" also contains a "&" ;)Thus it's the responsibility of the remote system that all special characters are converted to their entities inside text-nodes.
QString doesn't do any implicit entity conversations.
What errors do you get when using QDomDocument::setContent()?
-
I have finally a solution that I don't like much.
Posting it for any further comments.
I use QXmlStreamReader to read the document and allow it to fail.
I get the point of failure using characterOffset() . Using this offset peak into the buffer... if the error is correctable... correct it else report a failure.
If corrected then re-parse to check validity ...do this till everything is correct or a true error happens.