0

In camel we use validator:com/mypackage/myschema.xsd to do xml validation. Won't ValidatorResourceResolver will discover schema from xml's xsi:schemaLocation attribute?

what is the use of xsi:schemaLocation? Does camel xml parser uses this XSD or we have to explicitly call validator?

Poornan
  • 741
  • 2
  • 11
  • 25

1 Answers1

0

As far as I know, the schema location is not used. You have to call the validator explicitly.

That means if you got XMLs from different schemas, you have to lookup the namespace-identifier and based on that, use the correct schema for validation.

To lookup the namespace-identifier, you can use XPath

.setHeader("xml_namespace", xpath("namespace-uri(/*)").stringResult().saxon())

Like this the namespace is saved in the message header and you can use that later to decide what schema file you need to use for the validator. For example in a choice/when block directly in a route or in a Java bean that holds a Map with the namespace as key and the schema file path as value.

Finally, you can call the validator as a dynamic endpoint (notice the D in toD)

.toD("validator:${headers.schemafilepath}")
burki
  • 6,741
  • 1
  • 15
  • 31