开发者

Which Java xml framework can handle code generation with restrictions/extensions in schemas?

开发者 https://www.devze.com 2023-01-26 07:40 出处:网络
There is a set of XSD files, with the following types described in them: A is a complex type with various elements.

There is a set of XSD files, with the following types described in them:

A is a complex type with various elements. B restricts A, keeping only some of its elements C extends B, adding some elements.

So, this 开发者_StackOverflowmeans that a Java class generated by a tool using type C from the XML schema, is expected to include only those members of A which are kept by B, and the new ones added by C

To make things even more difficult, B actually changes minOccurs attribute of some of the elements.

Are there any frameworks out there which can handle this? I've tried EMF and restrictions are not even reflected to code.


Use Castor CodeGenerator. It's Nice. See http://www.castor.org/reference/html-single/index.html#xml.code.generator.examples.non-trivial


When using complex XSDs I had the best results with XMLBeans.

  • It has full XML Schema support.
  • It was the only framework which could generate correct code for the intricate xml schemas I had to use.

Another really useful feature is:

When unmarshalling an XML instance the full XML infoset is kept and is available to the developer. This is critical because because of the subset of XML that is not easily represented in java. For example, order of the elements or comments might be needed in a particular application.


Here's antoher alternative (for you to can choose one): The Axis2 DataBinding Framework (ADB) supports type hierarchy and custom restrictions .

Pros: It generates the full schema structure and implements getters and setters from each element. On the setters of every type y checks the schema defined restictions, and when the value to set doesn't match the restriction it throws an exception (at the very own set method), and it supports StAX for serialization/deserialization.

Cons: the generated code can result a bit too verbose, the validation exceptions are too few explicative, it's meant to be "simple" (so with complex type extensions or restrictions you could find some troubles), and it includes some dependencies with the ADB library (i.e. the generated beans implement the org.apache.axis2.databinding.ADBBean interface).

0

精彩评论

暂无评论...
验证码 换一张
取 消