Friday, 22 August 2014

libxml2 namespace prefix for schemaLocation is not defined





Few days ago I started to learn libxml2 for parsing xml documents on Linux (Ubuntu 14.04). But unfortunately I have a lot of problems with it.

First, I have an error message when I use function xmlParseDoc():

doc.xml:1: namespace error : Namespace prefix xsi for schemaLocation on OAI-PMH is not defined. /http://ift.tt/1zb6tHb http://ift.tt/1lkYiXZ" .



Second is an error when I try to validate xml-document via xsd. But I think this error is a result of first problem. This is an error message:

doc.xml:1: element OAI-PMH: Schemas validity error : Element 'OAI-PMH': No matching global declaration available for the validation root.



Please can everyone help and explain my fault?



There is parseFile() function:



bool parseFile(xmlDocPtr& doc, const char* filename) {
doc = xmlParseFile(filename);
if(doc == NULL) {
std::cout << "Document is not parsing successfully: " << filename << std::endl;
return false;
}
xmlNodePtr root = xmlDocGetRootElement(doc);
if(root == NULL) {
std::cout << "Empty document: " << filename << std::endl;
return false;
}
if(xmlStrcmp(root->name, (const xmlChar *)"OAI-PMH")) {
std::cout << "Document of the wrong type, root node != \"OAI-PMH\"" << std::endl;
return false;
}
return true;
}


There is validateDoc() function:



void validateDoc(xmlDocPtr doc) {
std::cout << "Start to validate doc func\n";
xmlSchemaParserCtxtPtr schemaParser = xmlSchemaNewParserCtxt("http://ift.tt/1lkYiXZ");
xmlSchemaPtr schema = xmlSchemaParse(schemaParser);
xmlSchemaValidCtxtPtr schemaValid = xmlSchemaNewValidCtxt(schema);
int result = xmlSchemaValidateDoc(schemaValid, doc);
std::cout << "Result: " << result << std::endl; // result is equal to 1845!
std::cout << "End validate doc func\n";


}


And this is a xml-document:



<OAI-PMH xsi:schemaLocation="http://ift.tt/1zb6tHb http://ift.tt/1zb6uLd;
<responseDate>2014-08-21T22:00:24.551Z</responseDate>
<request verb="Identify"/>
<Identify>
<repositoryName>Musketti KDK Data</repositoryName>
<baseURL>http://ift.tt/1lkYiY0;
<protocolVersion>2.0</protocolVersion>
<adminEmail>noreply@museo.fi</adminEmail>
<earliestDatestamp>1900-01-01T00:00:00.000Z</earliestDatestamp>
<deletedRecord>no</deletedRecord>
<granularity>YYYY-MM-DDThh:mm:ssZ</granularity>
<compression>NoCompression</compression>
</Identify>
</OAI-PMH>

No comments:

Post a Comment