[xml] XML Schema: Validating an instance document with multiple schemas

I’ve made a tremendous amount of progress in fitting libxml2 into our application’s XML processing model. I took the approach that Frank Gross suggested on my ‘multiple schema’ issue – namely, to modify the “main” schema on the fly with <xs:import namespace=”blah” schemaLocation=”blah”/> nodes for each secondary schema (reminder – having to do this is new to me because I’m used to MSXML’s “schema collection” object that performs the work of aggregating schemas for you).  


This works, but I’ve run into an issue: I have to reload the document after performing the in-memory modifications in order to pass parse validation of the schema itself. Any theories why this might be? I’ve used the element and doc dumping capabilities of the library and am confident that the runtime changes are correct – indeed they must be if I can dump to memory at runtime and reload/parse/validate.


Just to be sure I’m clear, this case fails:

1.) xmlReadFile (strPrimarySchemaFile, NULL, XML_PARSE_NONET)

2.) Add targetNamespace to xs:schema node for primary schema, add <xs:import> nodes for secondary schemas

3.) call xmlSchemaNewDocParserCtxt to create parser context and xmlSchemaParse to parse the schema (which fails)

And this case succeeds:

1.) Call xmlReadFile like before

2.) Add targetNamespace and xs:import’s exactly like above

3.) Call xmlDocDumpMemory to dump to a xmlChar buffer, xmlDocFree to free the original doc, and xmlReadDoc load the dumped buffer back into a DOM

4.) Call xmlSchemaNewDocParserCtxt and xmlSchemaParse as above (and ultimately xmlSchemaValidateDoc), which now succeed


Thanks again,

- Paul




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]