将 Jing 与 Google App Engine 结合使用。无法加载给定 Relax NG 架构的 SchemaFactory
好的,这就是我想要实现的目标的不足之处。我正在开发一个小型 Google App Engine 应用程序,它可以根据给定的特定对象生成 XML。
现在,我遇到了问题,因为我需要使用 Relax NG 架构并根据我的 Document 对象对其进行验证。这在我的本地计算机(Eclipse Helios Java EE、Mac OS X Snow Leopard、Google Web Toolkit 2.2.0、App Engine 1.4.2)上运行良好,但是一旦我部署到 App Engine,我的代码就会失败并抛出 IllegalArgumentException 。
具体的异常是这样的:
java.lang.IllegalArgumentException: No SchemaFactory that implements the schema language specified by: http://relaxng.org/ns/structure/1.0 could be loaded
它抱怨的具体代码行如下:
System.setProperty(SchemaFactory.class.getName() + ":" + XMLConstants.RELAXNG_NS_URI, "com.thaiopensource.relaxng.jaxp.CompactSyntaxSchemaFactory");
SchemaFactory schemaFac = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
最后一行是抛出异常的行。
我尝试过在网上查找,并在几个谷歌群组中发帖,但没有人提出想法。
注意:我从这个示例中使用了上面的一些代码:如何使用 RELAX NG 架构和 JAXP 验证 XML 文档?
我怀疑 App Engine 未加载 Jing。由于某种原因罐子。我不知道如何检查它是/不是。
任何帮助将不胜感激!谢谢!
Okay, so here's the short of what I'm trying to achieve. I am developing a small Google App Engine application that generates XML given a particular object.
Now, I run into issues because I need to use a Relax NG schema and validate it against my Document object. This works fine on my local machine (Eclipse Helios Java EE, Mac OS X Snow Leopard, Google Web Toolkit 2.2.0, App Engine 1.4.2), but as soon as I deploy to App Engine, my code fails and throws an IllegalArgumentException.
The specific exception is this:
java.lang.IllegalArgumentException: No SchemaFactory that implements the schema language specified by: http://relaxng.org/ns/structure/1.0 could be loaded
The specific line(s) of code that it is complaining about are the following:
System.setProperty(SchemaFactory.class.getName() + ":" + XMLConstants.RELAXNG_NS_URI, "com.thaiopensource.relaxng.jaxp.CompactSyntaxSchemaFactory");
SchemaFactory schemaFac = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
The last line is the line that throws the Exception.
I have tried looking online, and posted in several Google Groups, but no one came forth with an idea.
Note: I took the use of some of the above code from this example: How to validate an XML document using a RELAX NG schema and JAXP?
My suspicion is that App Engine is not loading Jing.jar for some reason. I don't know how I can check that it is/isn't.
Any help would be appreciated! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这篇文章只是为了澄清。
我使用 Jing 和 Relax NG 验证 XML 文档的常用方法是:
现在,在 App Engine 中,前两行不起作用,并导致抛出 IllegalArgumentException,就像您所说的那样。所以交换它们
就可以了。摘要(包括导入):
请注意,这是针对 XML 语法中的架构。对于紧凑语法,请将 XMLSyntaxSchemaFactory 与 CompactSyntaxSchemaFactory 交换。
This post just to clarify.
The usual way I would validate an XML document with Jing and Relax NG is:
Now, in App Engine, the first two lines don't work, and cause an IllegalArgumentException to be thrown, like you said. So exchanging them with
does the trick. Summary (including imports):
Note that this is for schemas in XML syntax. For compact syntax, exchange XMLSyntaxSchemaFactory with CompactSyntaxSchemaFactory.
我猜想
System.setProperty()
失败了,或者没有正确使用。根据文档:如果 SchemaFactory 是 JDK 的一部分(我认为是),您可能无法重置它。不过,如果您在 appconfig 文件中设置系统属性,效果可能会更好,因为这可能会在启动顺序的早期发生变化。
I'd guess that
System.setProperty()
is failing, or rather not being used correctly. According to the docs:If SchemaFactory is part of the JDK (which I think it is), you may not be able to reset it. However, you may have more luck setting the system property in your appconfig file, as this might get changed earlier in the startup sequence.
好吧,我实际上找到了一种解决方法,可以完全消除 System.setProperty 的(实际上是黑客式的)使用。
原来Jing有一个小类,叫做“CompactSyntaxSchemaFactory”。
我是这样使用它的:
非常有效。
Well, I actually found a workaround of sorts that completely takes out the (practically hackish) use of System.setProperty.
It turns out that Jing has a little class called "CompactSyntaxSchemaFactory".
Here is how I used it:
Worked like a charm.