将 Jing 与 Google App Engine 结合使用。无法加载给定 Relax NG 架构的 SchemaFactory

发布于 2024-10-17 04:43:02 字数 1147 浏览 7 评论 0原文

好的,这就是我想要实现的目标的不足之处。我正在开发一个小型 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 技术交流群。

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

发布评论

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

评论(3

铁轨上的流浪者 2024-10-24 04:43:02

这篇文章只是为了澄清。

我使用 Jing 和 Relax NG 验证 XML 文档的常用方法是:

System.setProperty(SchemaFactory.class.getName() + ":" + XMLConstants.RELAXNG_NS_URI, "com.thaiopensource.relaxng.jaxp.XMLSyntaxSchemaFactory");
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
Schema schema = factory.newSchema(new File("path/to/schema.rng"));

Validator validator = schema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlString)));

现在,在 App Engine 中,前两行不起作用,并导致抛出 IllegalArgumentException,就像您所说的那样。所以交换它们

SchemaFactory factory = new XMLSyntaxSchemaFactory();

就可以了。摘要(包括导入):

import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import com.thaiopensource.relaxng.jaxp.XMLSyntaxSchemaFactory;

SchemaFactory factory = new XMLSyntaxSchemaFactory();
Schema schema = factory.newSchema(new File("path/to/schema.rng"));

Validator validator = schema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlString)));

请注意,这是针对 XML 语法中的架构。对于紧凑语法,请将 XMLSyntaxSchemaFactory 与 CompactSyntaxSchemaFactory 交换。

This post just to clarify.

The usual way I would validate an XML document with Jing and Relax NG is:

System.setProperty(SchemaFactory.class.getName() + ":" + XMLConstants.RELAXNG_NS_URI, "com.thaiopensource.relaxng.jaxp.XMLSyntaxSchemaFactory");
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
Schema schema = factory.newSchema(new File("path/to/schema.rng"));

Validator validator = schema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlString)));

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

SchemaFactory factory = new XMLSyntaxSchemaFactory();

does the trick. Summary (including imports):

import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import com.thaiopensource.relaxng.jaxp.XMLSyntaxSchemaFactory;

SchemaFactory factory = new XMLSyntaxSchemaFactory();
Schema schema = factory.newSchema(new File("path/to/schema.rng"));

Validator validator = schema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlString)));

Note that this is for schemas in XML syntax. For compact syntax, exchange XMLSyntaxSchemaFactory with CompactSyntaxSchemaFactory.

书间行客 2024-10-24 04:43:02

我猜想 System.setProperty() 失败了,或者没有正确使用。根据文档

所有系统属性和环境变量都是您的应用程序私有的。设置系统属性仅影响应用程序对该属性的视图,而不影响 JVM 的视图。

如果 SchemaFactory 是 JDK 的一部分(我认为是),您可能无法重置它。不过,如果您在 appconfig 文件中设置系统属性,效果可能会更好,因为这可能会在启动顺序的早期发生变化。

I'd guess that System.setProperty() is failing, or rather not being used correctly. According to the docs:

All system properties and environment variables are private to your application. Setting a system property only affects your application's view of that property, and not the JVM's view.

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.

温柔戏命师 2024-10-24 04:43:02

好吧,我实际上找到了一种解决方法,可以完全消除 System.setProperty 的(实际上是黑客式的)使用。

原来Jing有一个小类,叫做“CompactSyntaxSchemaFactory”。

我是这样使用它的:

    DocumentBuilderFactory docFactory = null;

    CompactSyntaxSchemaFactory scReader = new CompactSyntaxSchemaFactory();
    URL relaxSchemaURL = new URL("http://example.com/myschema.rng");
    Schema2 relaxSchema = scReader.newSchema(relaxSchemaURL);

    docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setSchema(relaxSchema);

非常有效。

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:

    DocumentBuilderFactory docFactory = null;

    CompactSyntaxSchemaFactory scReader = new CompactSyntaxSchemaFactory();
    URL relaxSchemaURL = new URL("http://example.com/myschema.rng");
    Schema2 relaxSchema = scReader.newSchema(relaxSchemaURL);

    docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setSchema(relaxSchema);

Worked like a charm.

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