添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode . Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

I have a lot of pre-existing code which uses QDomDocument and 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 QXmlParseException documentation, 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.

@Robert-Hairgrove said in QDomDocument::setContent() and error parsing:

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.

Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
Visit the Qt Academy at https://academy.qt.io/catalog

@Christian-Ehrlicher Thank you.

I suppose I misunderstood the documentation here?
https://doc.qt.io/qt-5/qtxml-module.html#details

But I am glad to know that it is still officially supported. I will take a look at Qt XML Patterns now.

@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".

Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
Visit the Qt Academy at https://academy.qt.io/catalog

@Christian-Ehrlicher Thank you.

I assume you meant to write: "Don't use Qt6, or else use an 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 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:

https://wiki.qt.io/New_Features_in_Qt_6.0#Removed_Modules