XML验证
我想根据提供的 RELAXNG 架构验证 XML 文件。 在网上搜索给了我提示,通过提供适当的架构语言,使用 SchemaFactory 创建架构实例。 因此,根据我的要求,我使用:
SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
但在运行时抛出以下异常:
线程“main”中的异常 java.lang.IllegalArgumentException: No SchemaFactory实现由以下指定的模式语言:http://relaxng.org/ns/struct/1.0 可以加载
在 javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:207)
我正在使用 Java6 并观察到只有“W3C_XML_SCHEMA_NS_URI”有效。 其余所有架构 URI 都会引发类似的异常。
我对使用 XML 验证 API 还很陌生。 如果我做得不正确,有人可以为我提供适当的用法吗?
谢谢& 问候,
科亚
I want to validate an XML file against RELAXNG schema provided. Searching on the net gave me hints to create a Schema instance using SchemaFactory by providing the appropriate Schema Language. So as per my requirement I used:
SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
But the following exception was thrown at run:
Exception in thread "main" java.lang.IllegalArgumentException: No SchemaFactory that implements the schema language specified by: http://relaxng.org/ns/structure/1.0 could be loaded
at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:207)
I am using Java6 and observed that only 'W3C_XML_SCHEMA_NS_URI' works. Rest all the schema URIs throws the similar exception.
I am fairly new to using the XML validation APIs. Can someone please provide me the appropriate usage in case I am not doing it correctly?
Thanks & Regards,
Keya
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
RNG 在 Java API 中的支持很差,它从未真正受到关注。 据我所知,没有 Java API 实现可以处理它。 我建议将架构转换为 XML 架构(使用 Trang 或类似方法),然后验证反对这一点。
RNG is poorly supported in Java APIs, it never really got traction. I know of no Java API implementations that handle it. I suggest converting the schema to XML Schema (using Trang or similar) and then validating against that.
RNG 的支持不如 XML Schema 广泛。 您应该始终首先考虑使用 XSD。
RNG is not supported as widely as XML Schema. You should always think of using XSD first.
msv 采用 Java 语言; 我想它有一个清晰的 API 您可以使用,但我只在命令行和脚本中使用过它。
msv is in Java; I suppose it has a clear API you can use, but I've only ever used it on the command line and in scripts.
Kohsuke Kawaguchi 显然为 jaxp 编写了一个适配器库以使用relaxng验证器,请参阅 此处和此处
Kohsuke Kawaguchi apparently wrote a adapter library for jaxp to use a relaxng validator, see here and here
我已经使用 Java 6 成功根据基于 XML 的 RelaxNG 模式验证文档,请查看:
如何使用 RELAX NG 模式和 JAXP 验证 XML 文档?
不知道它是否相关,只是指出:-)。
I've had success in validating a document against a XML-based RelaxNG Schema using Java 6, check out :
How to validate an XML document using a RELAX NG schema and JAXP?
Don't know if it's relevant, just pointing out :-).