问题描述
在Java 6中,整个xerces XML解析器/序列化器实现现在位于Java运行时(rt.jar)中。这些包已经在com.sun。*命名空间下移动,这使它们不受限制,以便在客户端代码中显式引用。使用解析器时这不是问题,解析器是通过javax API定义的工厂实例化的。
In Java 6, the entire xerces XML parser/serializer implementation is now in the Java runtime (rt.jar). The packages have been moved under the com.sun.* namespace, which places them off-limits for explicit reference within client code. This is not a problem when using the parser, which is instantiated via javax API-defined factories.
但是,我们的代码也使用xerces序列化(org.apache.xml.serialize。*)。 AFAICT,没有用于创建Serializer和OutputFormat实例的javax.xml API定义工厂。这似乎意味着获得一个的唯一方法是显式调用com.sun.org.apache.xml.serialize。* API。
However, our code also uses xerces serialization (org.apache.xml.serialize.* ). AFAICT, there are no javax.xml API-defined factories for creating instances of Serializer and OutputFormat. This seems to imply that the only way to get one is to explicitly call the com.sun.org.apache.xml.serialize.* APIs.
我发现javax.xml.stream中的序列化类,但它们似乎没有像xerces OutputFormat类那样提供任何输出格式化控件。
I've found the serialization classes in javax.xml.stream, but they don't seem to provide any output-formatting control like the xerces OutputFormat class.
问题:
有没有办法访问xerces序列化功能( 通过javax标准API在rt.jar中 ,不包括xerces.jar,也没有显式实例化com.sun。*类?
Is there a way to access the xerces serialization functionality (which is in rt.jar) via a javax standard API, without including xerces.jar and also without explicitly instantiating com.sun.* classes?
如果没有,是否有符合javax API的方法来实现相同的效果?
If not, is there an javax API-compliant way to achieve the same effect?
推荐答案
如果你想使用Xerces的功能不是通过官方的 java。*
或 javax。*
API公开,那么你唯一真正的解决方案是包括Xerces作为第三方库。以任何方式访问JRE内部版本的Xerces都是一件危险的事情,因为没有什么能保证有效的JRE甚至有这些类(备用JRE甚至同一JRE的其他版本可能使用不同的实现来实现JAXP API甚至只需将其移至另一个包裹。)
If you want to use a Xerces feature that's not exposed through an official java.*
or javax.*
API, then your only real solution is to include Xerces as a third-party library. Accessing the JRE-internal version of Xerces in any way would be a dangerous thing, since nothing guarantees that a valid JRE even has those classes (alternate JREs and even other versions of the same JRE might implement the JAXP APIs using a different implementation or even just move it to another package).
这篇关于Java 6中的xerces序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!