如何将 JAXB 对象编组到 XOM?
我试图弄清楚需要将哪些位插入在一起才能将 JAXB POJO 编组到 XOM 文档,反之亦然。
JAXB Marshaller
接口的编组方法采用各种目标,例如 Result
,但它们都没有 XOM 适配器。令人恼火的是,XOM API 确实有一个 XOMResult
实现,但它受包保护,并且仅在内部使用。
是否有其他方法可以在不诉诸字符串或字节缓冲区的情况下编组到 XOM 或从 XOM 编组?
I'm trying to figure out what bits I need to plug together to marshal a JAXB POJO to a XOM document, and vice versa.
The JAXB Marshaller
interface's marshal methods take various targets, such as Result
, but none of them have a XOM adapter. Irritatingly, the XOM API does have a XOMResult
implementation, but it's package protected, and only used internally.
Is there some other way I can marshal to/from XOM without resorting to String or byte buffers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否反对使用 DOM 来完成此任务,因为您可能正在使用 XOM 来避免 DOM!无论如何,按照描述使用 JAXB Binder 此处以及 XOM 的 DOMConverter,您可以从 JAXB 到 DOM 再到 XOM,而无需使用 String 或字节缓冲区。
遗憾的是,XOM 没有从 SAX ContentHandler 创建 XOM 文档的实用程序,因为 JAXB 还支持编组到该对象的实例。 XOM 有一个 SAXConverter 可以创建 ContentHandler来自文档,但反之则不然。
这是与此相关的线程 XOM-interest 邮件列表。
I'm not sure if you are adverse to using DOM to accomplish this, as you're probably using XOM to avoid DOM! Anyway, using a JAXB Binder as described here along with XOM's DOMConverter, you can go from JAXB to DOM to XOM without using a String or a byte buffer.
It is too bad that XOM doesn't have a utility to create a XOM Document from a SAX ContentHandler, since JAXB also supports marshalling to an instance of that object. XOM has a SAXConverter that can create a ContentHandler from a Document, but not the other way around.
Here's a thread that relates to this on the XOM-interest mailing list.
我发现旧项目 nux:
a http://acs.lbl.gov/software/nux//api/nux/xom/pool/XOMUtil。 html
jaxbMarshal/jaxbUnmarshal 使用 DOMConverter ;-(
b. http://acs.lbl.gov/software/nux/api/nux/xom/io/StaxUtil.html
...还包括使用 StAX 解析器而不是 SAX 解析器的 XOM Builder 实现;加上从底层 XOM 文档或片段读取的 XMLStreamReader 实现;加上其他工具。
StaxUtil.createXMLStreamReader(节点根)
构造并返回一个 StAX XMLStreamReader 拉解析器实现,该实现从底层 XOM 节点读取;通常是文档或片段(子树);非常适合将 XOM 树高效转换为 SOAP/AXIOM、JAXB 2、JiBX 或 XMLBeans,例如通过 Unmarshaller(可能与 StreamingPathFilter 结合使用)增量转换 XQuery 结果时。
这可能有帮助吗?
I found old project nux:
a http://acs.lbl.gov/software/nux//api/nux/xom/pool/XOMUtil.html
jaxbMarshal/jaxbUnmarshal use DOMConverter ;-(
b. http://acs.lbl.gov/software/nux/api/nux/xom/io/StaxUtil.html
...also includes a XOM Builder implementation that uses a StAX parser instead of a SAX parser; plus a XMLStreamReader implementation reading from an underlying XOM Document or fragment; plus other tools.
StaxUtil.createXMLStreamReader(Node root)
Constructs and returns a StAX XMLStreamReader pull parser implementation that reads from an underlying XOM Node; typically a Document or fragment (subtree); Ideal for efficient conversion of a XOM tree to SOAP/AXIOM, JAXB 2, JiBX or XMLBeans, for example when incrementally converting XQuery results via an Unmarshaller, perhaps in combination with a StreamingPathFilter.
May be this can help?