As part of my XML transform (using XSL), I'm creating an attribute for the schema location so the the result of the transform can be validated. However, as I'm trying to run this as a self-contained test I want to be able to set the appropriate attribute/value for the schema location to be off my CLASSPATH.
作为我的XML转换(使用XSL)的一部分,我正在为模式位置创建一个属性,以便可以验证转换的结果。但是,当我尝试将其作为一个独立的测试运行时,我希望能够将模式位置的相应属性/值设置为关闭我的CLASSPATH。
After a bit of Googling I've tried various schemaLocation attributes, the latest attempt being:
经过一段谷歌搜索,我尝试了各种schemaLocation属性,最新的尝试是:
..
<xsl:attribute name="xsi:external-noNamespaceSchemaLocation">
<xsl:value-of select="$schemaLocation"/>
</xsl:attribute>
..
Which after the transform results in:
变换后的结果如下:
<?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've double checked that my emrException_1_0.xsd file is clearly in the CLASSPATH when the validator runs. It's a DOM validator and I'm using Xerces 2.9.1/Xalan 2.7.1, the result I get is:
我已经仔细检查过,当验证程序运行时,我的emrException_1_0.xsd文件显然位于CLASSPATH中。它是一个DOM验证器,我使用的是Xerces 2.9.1 / Xalan 2.7.1,我得到的结果是:
Caused by: org.xml.sax.SAXParseException:
cvc-elt.1: Cannot find the declaration of element 'emrException'.
However, when I swap to using a schema location where the XSD file is read off the file system or an external URL, then the validator runs fun.
但是,当我交换使用从文件系统或外部URL读取XSD文件的架构位置时,验证器运行起来很有趣。
How can I get the XSD to be read off my CLASSPATH?
如何从CLASSPATH中读取XSD?
1 个解决方案
#1
1
One way is to implement your own LSResourceResolver and LSInput, so that the systemId that is passed in can be resolved however you would want.
一种方法是实现自己的LSResourceResolver和LSInput,以便可以根据需要解析传入的systemId。
#1
1
One way is to implement your own LSResourceResolver and LSInput, so that the systemId that is passed in can be resolved however you would want.
一种方法是实现自己的LSResourceResolver和LSInput,以便可以根据需要解析传入的systemId。