How can I refer to XSD with CLASSPATH to validate my XML?

As part of my XML transformation (using XSL), I create an attribute for the layout of the schema so that the result of the transformation can be verified. However, since I am trying to run this as a standalone test, I want to be able to set the appropriate attribute / value for the location of the schema from my CLASSPATH.

After a bit of googling, I tried various schemaLocation attributes, the last attempt:

.. <xsl:attribute name="xsi:external-noNamespaceSchemaLocation"> <xsl:value-of select="$schemaLocation"/> </xsl:attribute> .. 

What after conversion leads to:

 <?xml version="1.0" encoding="UTF-8"?> <emrException xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:external-noNamespaceSchemaLocation="emrException_1_0.xsd"> .. <!-- more well-formed XML --> </emrException> 

I double-checked that my emrException_1_0.xsd file is explicitly in CLASSPATH when starting authentication. This is a DOM validator, and I am using Xerces 2.9.1 / Xalan 2.7.1, the result of which is:

 Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'emrException'. 

However, when I switch to using a schema location where the XSD file is read from the file system or an external URL, then the validator works fun.

How can I get an XSD to read from my CLASSPATH?

+4
source share
1 answer

One way is to implement your own LSResourceResolver and LSInput, so that the system identifier that is passed can be resolved, but you want to.

+1
source

Source: https://habr.com/ru/post/1337523/


All Articles