如何在我的 Web 应用程序中使用带有路径的 xsd 架构

发布于 2024-09-24 07:41:32 字数 746 浏览 0 评论 0原文

我正在使用 JDOM 解析器来读取 XML,它包括使用 xsd 模式的验证。

一般来说,为了将 xsd 的路径设置为解析器,根据文档,语法是 -

        SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
        builder.setFeature("http://apache.org/xml/features/validation/schema", true);
        builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", <schema_path>);

它可以通过将 schema_path 设置为以 http: 开头的 url 或绝对路径(即c:/myFolder/schema.xsd)
我的问题 - 如何使用位于我的 Web 应用程序中的 xsd,并且它的路径位于 Web 根目录下的某个位置?是否可以提供 JDOM 构建器的相对路径?

能够回答这个问题的人也可能会帮助解决我在使用 xsd 时遇到的另一个问题:
在此线程中

I am using JDOM parser that read my XML and it include validation using xsd schema.

generally, in order to set the path of the xsd to the parser the syntax, according to the documentation is-

        SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
        builder.setFeature("http://apache.org/xml/features/validation/schema", true);
        builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", <schema_path>);

It can work by setting the schema_path to be either url starting with http: or absolute path (i.e. c:/myFolder/schema.xsd)
My question - how can I use an xsd that is located withing my web-application and the path to it will be somewhere beneath the Web root? is it possible to provide relative path to the JDOM builder?

People that are capable of answer this question might also assist in solving another problem I faced regard using xsd:
in this thread here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-10-01 07:41:32

您不能提供相对路径作为字符串参数。

要获取 WEB-INF 文件夹的真实路径,请尝试

getServletContext().getRealPath("/WEB-INF")

要获取 WEB-INF/my.xsd 的真实路径,请使用

getServletContext().getRealPath("/WEB-INF/my.xsd")

getRealPath 方法将返回服务器文件系统上的绝对文件路径。

如果将架构​​添加为 jar 资源,请阅读

You can not provide relative path as String argument.

To get real path to WEB-INF folder, try

getServletContext().getRealPath("/WEB-INF")

To get real path to WEB-INF/my.xsd, use

getServletContext().getRealPath("/WEB-INF/my.xsd")

getRealPath method will return the absolute file path on the server's filesystem.

If you add your schema as jar resources, read this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文