有没有一种将XML解析为Java对象的声明方式? [英] Is there a declarative way to parse XML to Java objects?

查看:172
本文介绍了有没有一种将XML解析为Java对象的声明方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将XML文件的导入功能写入Java应用程序.我正在使用 XOM 来解析XML文件.解析XML的代码不容易理解,它是一些硬编码的.getChild(3),依此类推.与声明性XML文档相比,很难遵循该代码.

I'm writing an import function of XML files to my Java application. I am using XOM to parse the XML files. The code for parsing the XML is not easy to understand, it is some hardcoded .getChild(3) and so on. It is hard to follow the code compared to the declarative XML document.

是否存在将XML文档解析为Java对象的更可维护的方法?我想以一种更具说明性的方式来使用它,在这里我可以指定哪些标签对应于哪些Java类.

Isn't there a more maintainable way to parse XML documents to Java objects? I would like to have it in a more declarative way, where I can specify what tags corresponds to what Java classes.

推荐答案

我终于发现 XStream 很简单以声明的方式使用和解析XML.

I finally found XStream that was easy to use and parses the XML in a declarative way.

这篇关于有没有一种将XML解析为Java对象的声明方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆