I'm trying to validate a XML with a XSD schema in Qt.
XML and XSD seems to be valid, according to W3C schema validator.
This is the code where I perform the validations:
bool XMLFOMParser::isWellFormed(const std::string& text) const {
QXmlSchema schema;
bool ok = schema.load(QByteArray(SOMSchema_xsd));
std::cout<< SOMSchema_xsd << std::endl << "--------------" << std::endl;
std::cout << text << std::endl << "---------------" << std::endl;
QXmlSchemaValidator validator(schema);
bool result = validator.validate(QByteArray(text.data()));
return result;
}
text
contains the XML text that must be validates. SOMSchema_xsd
contains the xsd schema text.
When I load the schema into QXmlSchema
the variable ok
is true, and with the cout
I can see that both schema and xml are loaded correctly. I see entirely them.
When I perform the validation, result
is false, and in de console I can see following messages:
Error XSDError in http://standards.ieee.org/downloads/1516/1516.2-2010/IEEE1516-DIF-2010.xsd, at line 1, column 0: Premature end of document.
Error XSDError in file:///my/program.exe, at line 2, column 251: Loaded schema file is invalid.
I don't know why I'm obtaining these errors since:
cout
);QXmlSchema
gives me no errors when the xsd is loadedWhat I'm doing wrong?
It looks like your schema referes to another schema, namely http://standards.ieee.org/downloads/1516/1516.2-2010/IEEE1516-DIF-2010.xsd
. But as you can verify yourself, that is not a valid link to an XSD.
However, in order to validate, the validator must know the referenced elements of that schema. As it tries to load it, you get your error.
You should install an QAbstractUriResolver
, that can serve that request, e.g. from a local file