将 Java 对象序列化为 xml 并返回(XML 配置)
我正在寻找一个 XML 序列化框架,它可以选择 XML 配置而不是注释来命名类和字段。
我查看了 Simple 和 XStream 但没有找到方法。我想我可以使用 Spring IOC 和 XStreams 别名,但如果有任何框架可以为我做到这一点,那当然会更好:)
I am looking for a XML serialization framework which has an option for a XML configuration instead of annotation to name classes and fields.
I looked at Simple and XStream but I didn't find a method to do it. I suppose I could use Spring IOC and XStreams aliasing, but if there's any frameworks, which could do this for me, it would of course be better :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JiBX 是一个 Java 到 XML 绑定框架,您可以在其中使用 XML 绑定。 XML 有点冗长,有时可能有点难以管理,但任何 XML 配置都是如此。
我知道你说过你看过xstream,但是一些xstream配置可以通过代码完成(不是配置,而是通过配置xstream对象,例如省略字段)。我不确定这对您来说是否足够,但是您可以在没有注释的情况下执行一些操作。
JiBX is a Java to XML Binding framework in which you can use XML bindings. The XML is a bit verbose and can sometimes be a little hard to manage, but that can be true of any XML configuration.
I know you said you've looked at xstream, but some xstream configuration can be done through code (not configuration, but through configuring the xstream object, for example, omitting fields). I'm not sure if that's enough for you, but you can do some things without the annotations.
EclipseLink JAXB (MOXy) 有一个基于 JAXB 元数据的外部化绑定文件
示例文件看起来像:
有关更多信息,请参阅:
- http://wiki.eclipse.org/EclipseLink/Examples/MOXy /EclipseLink-OXM.XML
EclipseLink JAXB (MOXy) has a externalized binding file based on the JAXB metadata
A sample file looks something like:
For more information see:
- http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLink-OXM.XML
我喜欢 XStream,因为它主要是Just WorksTM。
我自己没有尝试过,也没有考虑过很多,但是您是否考虑过使用 XStream 来处理实际数据及其自身的配置?我认为您可以使用 XStream 读取配置文件,然后使用从中获取的(简单的
String
)数据作为alias()
方法调用之前的参数处理数据。I love XStream because it mostly Just WorksTM.
I haven't tried this myself or given it a lot of thought, but have you considered using XStream both for the actual data and its own configuration? I'm thinking you could use XStream to read a configuration file, and then use the (simple
String
) data obtained therefrom as the arguments toalias()
method calls prior to processing the data.