I'm trying to read and validate xml document that has external entites. But I have no succes with both reading and validating. I used this to create a test example.
Test xml:
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE doc [
<!ENTITY otherFile SYSTEM "otherFile.xml">
]>
<doc>&otherFile;</doc>
Other xml:
<baz>this is my content</baz>
Test xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="doc">
<xs:complexType>
<xs:sequence>
<xs:element ref="baz"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="baz" type="xs:string"/>
</xs:schema>
First, I try to read the contents of test.xml using QDomDocument
:
QDomDocument doc;
doc.setContent(&testFile);
qDebug() << doc.toString();
But in the debug output I get raw text from test.xml. The external entity is not substituted.
Then I try to validate test.xml against test.xsd:
QXmlSchema schema;
bool res = schema.load(&xsdFile, QUrl::fromLocalFile(xsdPath));
if (res == true)
{
QXmlSchemaValidator validator(schema);
if (validator.validate(&xmlFile, QUrl::fromLocalFile(xmlPath)))
{
qDebug() << "xml" << xmlName << "is valid";
}
else
{
qDebug() << "xml" << xmlName << "is invalid";
}
}
But validation fails and I get the following error:
Error XSDError in file:///..., at line 5, column 5: Element doc is missing child element.
Am I doing something wrong or Qt Xml module just doesn't support external entities?