Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QDomDocument::setContent() and error parsing
Robert Hairgrove last edited by Robert Hairgrove
I have a lot of pre-existing code which uses
QDomDocumentand related. classes (yes, I know it is deprecated, but we still use it). In my application, I load a configuration file which is in XML format. I also have an XML schema file (.xsd) which resides in the same folder as the XML file.
My question: When I call
setContent(), I can receive any error message as well as the line and column number in the file where the error occurred. According to the Qt documentation:
If a parse error occurs, this function returns false and the error message is placed in *errorMsg, the line number in *errorLine and the column number in *errorColumn (unless the associated pointer is set to 0); otherwise this function returns true. The various error messages are described in the QXmlParseException class documentation.
But looking at the different error messages in the
QXmlParseExceptiondocumentation, it appears to expect a DTD file when loading the XML. Does it also validate against a schema file if the XML includes a reference to it? Or do I have to do this separately?
It would be enough for my application to know whether validation succeeded or not; line and column numbers would also be good to have, but not vitally important.
yes, I know it is deprecated, but we still use it
where did you read this?
Does it also validate against a schema file if the XML includes a reference to it?
afaics no, that's what Qt XML Patterns was for.
@Christian-Ehrlicher Thank you.
I suppose I misunderstood the documentation here?
But I am glad to know that it is still officially supported. I will take a look at Qt XML Patterns now.
@Robert-Hairgrove Do you mean "Note that the module will not receive additional features anymore"? This does not mean it is depricated.
@jsulm Yes, that is what I thought. Good to know that it is not deprecated.
@Christian-Ehrlicher Now that Qt 6.0 has been released, I see that the XML patterns module was removed entirely from this version of Qt. What do I need to do, building with Qt 6, in order to validate an XML document against a schema XSD document stored in Qt resources, for example? I haven't found any relative documentation which explains how to compensate for the removal of XML patterns.
Resetting this thread to "unsolved".
@Robert-Hairgrove Don'T use Qt6 or an external xsd validation library. You will not get it back in Qt6 except you write it on your own.
@Christian-Ehrlicher Thank you.
I assume you meant to write: "Don't use Qt6, or
else usean external xsd validation library"?
I know that I could do this with Xerces, but would like to avoid the dependency if I can. Does anyone have suggestions for a lightweight external library? It should work on Linux and Windows, if possible.
JonB last edited by JonB
I feel your pain. We won't be thanked/will be shot down for saying this, but if you are saying the
QXml...classes are gone from Qt 6(?) that is a sad, retrograde step for those of us who use XML. In that case I just hope they drop the JSON support too....
@JonB The removed features are listed here. There are still classes which are named beginning with
QXml..., but I don't know if they still work as they did before:
I bit the bullet and now am using Xerces. It's fairly easy to use, but quite a large library to install. At least it works on both Windows and Linux, and the licensing is agreeable.