Search code examples
c++xercesvalidating

Validating against multiple xml schemas with Xerces DOM parser


I was wondering if there was a way to validate against multiple xml schemes using Xerces DOM parser in c++?

Here is the use-case: I want to be able to parse multiple xml files against its corresponding xsd schema. However, when I initially look at each xml file, I do not know what file it is until I parse it, hence I cannot link a static xsd file to it. Is there a way of saying, I want to validate each xml file against xsd1 or xsd2 or etc...

After reading around it appears the settings of the parser 'setExternalSchemaLocation' is able to hold a list of schemes but when I do this in my code, it doesn't validate correctly.

parser->setExternalSchemaLocation("http://www.somelocation schema.xsd http://www.somelocation schema1.xsd");

The schema works by itself if I did

parser->setExternalSchemaLocation("http://www.somelocation schema.xsd");

So I am certain there is no error in my xml or xsd file.

Any insights into how to validate against multiple xml schemas?


Solution

  • The code does not work if each xml is in the same namespace. Each xml file must be in a different namespace in order for the code above to work.

    parser->setExternalSchemaLocation("http://www.somelocation schema.xsd http://www.somelocation1 schema1.xsd");