Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

cannot load xsd file that imports another xsd



  • Hi, i have to load an xml schema file to validate my xml file. I tried with Qt 5.8 and 5.10.1 (atm i have only those installed) and i have the same problems i'm gonna explain here. Here is the code i use to load the schema:

    QXmlSchema schema;
    QFile schemaFile("path_to_xsd");
    schemaFile.open(QIODevice::ReadOnly);
    if (schemaFile.isOpen())
        schema.load(&schemaFile);
    

    inside the xsd file i have an import statement like this:

    <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
    

    and here is the xml.xsd file:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">
      <xs:annotation>
    		<xs:documentation></xs:documentation>
    	</xs:annotation>
    	<xs:attribute name="lang" type="xs:language">
    		<xs:annotation>
    			<xs:documentation></xs:documentation>
    		</xs:annotation>
    	</xs:attribute>
    	<xs:attribute name="space" default="preserve">
    		<xs:simpleType>
    			<xs:restriction base="xs:NCName">
    				<xs:enumeration value="default"/>
    				<xs:enumeration value="preserve"/>
    			</xs:restriction>
    		</xs:simpleType>
    	</xs:attribute>
    	<xs:attributeGroup name="specialAttrs">
    		<xs:attribute ref="xml:lang"/>
    		<xs:attribute ref="xml:space"/>
    	</xs:attributeGroup>
    </xs:schema>
    

    If i try to add those two xsd file as resources in my project and use a relative path, i noticed that in XsdSchemaParser::parseImport() function in qxsdschemaparser.cpp at line 683 the assert

    Q_ASSERT(m_documentURI.isValid());
    

    fails because m_documentURI is not setted then not valid.
    I tried to use absolute paths both in c++ code and xml import statement (schemaLocation). The assert above is not executed, but when the parseImport() function tries to parse the xml.xsd file, it fails because of "Premature end of Document".
    Is there something i did wrong? Any suggestion?


  • Lifetime Qt Champion

    Hi,

    Can you provide a minimal compilable example that illustrate that behaviour ?


Log in to reply