Java XML Binding [closed]

2019-01-13 00:01发布

What are you using for binding XML to Java? JAXB, Castor, and XMLBeans are some of the available choices. The comparisons that I've seen are all three or four years old. I'm open to other suggestions. Marshalling / unmarshalling performance and ease of use are of particular interest.

Clarification: I'd like to see not just what framework you use, but your reasoning for using one over the others.

11条回答
疯言疯语
2楼-- · 2019-01-13 00:02

I've used Jaxb with varying success. At the time (a couple of years back) the overall documentation was lackluster and the basic usage documentation (including where to download implementations) was difficult to find or varied.

The parser which wrote the Java classes was quite good with little discrepancy against the original XSD (though I think it had problems supporting abstract XML elements).

I haven't used it since, but I have an upcoming project which will require just such a framework and I will be interested to know how anyone else fairs with the above.

查看更多
贼婆χ
3楼-- · 2019-01-13 00:03

Jibx is what is used around here. It is very fast, but the bindings can be a little tricky. However, it is especially useful if you have XML schemas describing your domain objects, as it really maps well to XSD (there's even a beta tool XSD2Jibx which can take XSDs and create stub domain classes and mappings, which you can then take and coax to fit your existing domain model).

It manipulates bytecode, so it must be run after the initial compilation of the Java .class files. You can use the Maven plugin for it, or just use it directly (the Eclipse plugin didn't seem to work for me).

查看更多
Evening l夕情丶
4楼-- · 2019-01-13 00:04

We use xstream. Marshalling / unmarshalling is trivial. See their tutorial for examples.

查看更多
Viruses.
5楼-- · 2019-01-13 00:04

XmlBeans is a good choice especially if you have 'broken' XSD/WSDL files.

Don mentioned

EmployeesDocument empDoc = EmployeesDocument.Factory.parse(xmlFile);

..but it can also take a Node, or a File, or just about any source.

No fighting with namespaces, traverse to the object you want to unmarshall, and Factory.parse it.

Wish I had found it 2 weeks ago.

查看更多
Bombasti
6楼-- · 2019-01-13 00:05
趁早两清
7楼-- · 2019-01-13 00:17

I was wondering exactly the same question, and finally I found this performance tests made by IBM. http://www.ibm.com/developerworks/library/x-databdopt2/. JiBX is my choice I guess, hehe.

查看更多
登录 后发表回答