JMeter XML Schema的相对路径?


问题内容

我正在使用JMeter 2.6,并具有以下测试设置:

-
|-test.jmx
|-myschema.xsd

我已经设置了XML模式声明,并"myschema.xsd"在“文件名”字段中键入内容。不幸的是,这不起作用:

HTTP Request
Output schema : error: line=1 col=114 schema_reference.4:
Failed to read schema document 'myschema.xsd', because 
1) could not find the document; 
2) the document could not be read; 
3) the root element of the document is not <xsd:schema>.

我尝试将一些东西添加到中path,包括${__P(user.dir)}(指向home dir用户的)和${__BeanShell(pwd())}(不返回任何内容)。我通过给出绝对路径来使其正常工作,但是该脚本应该由其他人使用,所以这不好。

我可以使它使用在命令行中定义的属性值,但是出于同样的原因,我也想避免使用它。

在这种情况下,如何正确地将断言指向架构?


问题答案:

摘要: 最后,我在声明中使用了
http://path.to.schema/myschema.xsd
作为“文件名”参数。

说明: 按照Alies Belik的建议,我发现用于设置架构的代码如下所示:

DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
...
parserFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdFileName);

其中xsdFileName是一个字符串(属性字符串实际上是一个常量,为了便于阅读,我将其内联)。

根据例如此页面,该属性以字符串形式表示时将被解释为URI-
包括HTTP URL。由于已经有了可通过HTTP访问的模式,因此我选择了此解决方案。