I have a little project (on c++ linux ubuntu 14.04) where I trying to parse some XML document using libxml2. When I get .xml file I trying to validate it. But there are some nasty errors!
I found information about using a few .xsd schemas during validation. For this it is important to create .xsd document with "import" elements (for each of .xsd schema) that have 'schemaLocation' element.
There is my .xsd schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://osll.converter-schema"
targetNamespace="http://osll.converter-schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:OAI-PMH="http://www.openarchives.org/OAI/2.0"
xmlns:lido="http://www.lido-schema.org"
version="1.0" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.openarchives.org/OAI/2.0" schemaLocation="http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"/>
<xs:import namespace="http://www.lido-schema.org" schemaLocation="http://www.lido-schema.org/schema/v1.0/lido-v1.0.xsd"/>
</xs:schema>
There is c++ code for parsing .xsd schema using libxml2:
bool XmlDocument::validate(const char* fileSchema) {
std::cout << "Starting validate xml-document..";
xmlSchemaParserCtxtPtr schemaParser = xmlSchemaNewParserCtxt(fileSchema);
xmlSchemaPtr schema = xmlSchemaParse(schemaParser);
xmlSchemaValidCtxtPtr schemaValid = xmlSchemaNewValidCtxt(schema);
int result = xmlSchemaValidateDoc(schemaValid, xmlDocument);
if(result!=0) { std::cout << "Error! Code: " << result << std::endl; return false; }
else { std::cout << "Done!\n"; return true; }
return false;
}
And at last there is list of errors:
http://www.w3.org/1999/xlink.xsd:27: element import: Schemas parser warning : Element '{http://www.w3.org/2001/XMLSchema}import': Skipping import of schema located at 'http://www.w3.org/2001/xml.xsd' for the namespace 'http://www.w3.org/XML/1998/namespace', since this namespace was already imported with the schema located at 'http://www.w3.org/2001/03/xml.xsd'.
error : Operation in progress
I/O warning : failed to load external entity "http://schemas.opengis.net/gml/3.1.1/base/coverage.xsd"
http://schemas.opengis.net/gml/3.1.1/base/gml.xsd:16: element include: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}include': Failed to load the document 'http://schemas.opengis.net/gml/3.1.1/base/coverage.xsd' for inclusion. error : Operation in progress
I/O warning : failed to load external entity "http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"
response.xml:3: element OAI-PMH: Schemas validity warning : Element '{http://www.openarchives.org/OAI/2.0/}OAI-PMH', attribute '{http://www.w3.org/2001/XMLSchema-instance}schemaLocation': The document at location 'http://www.openarchives.org/OAI/2.0/OAI-PMH . xsd' could not be acquired.
response.xml:3: element OAI-PMH: Schemas validity error : Element '{http://www.openarchives.org/OAI/2.0/}OAI-PMH': No matching global declaration available for the validation root.
Please help to find bug, I will be very pleasure!