哪个 Java xml 框架可以处理模式中具有限制/扩展的代码生成?

发布于 2024-10-03 02:08:54 字数 245 浏览 1 评论 0原文

有一组 XSD 文件,其中描述了以下类型:

A 是具有各种元素的复杂类型。 B 限制 A,仅保留其部分元素 C 扩展了 B,添加了一些元素。

因此,这意味着由使用 XML 模式中的类型 C 的工具生成的 Java 类预计仅包含由 B 保留的 A 的成员以及由 C 添加的新成员

。实际上改变了一些元素的 minOccurs 属性。

有没有可以处理这个问题的框架?我尝试过 EMF,但限制甚至没有反映到代码中。

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 means 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不交电费瞎发啥光 2024-10-10 02:08:54

当使用复杂的 XSD 时,我使用 XMLBeans 得到了最好的结果。

  • 它具有完整的 XML 模式支持。
  • 它是唯一可以为我必须使用的复杂 xml 模式生成正确代码的框架。

另一个真正有用的功能是:

在解组 XML 实例时,完整的 XML 信息集将被保留并可供开发人员使用。这很重要,因为 XML 子集不容易用 java 表示。例如,特定应用程序中可能需要元素或注释的顺序。

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.

尛丟丟 2024-10-10 02:08:54

这是另一种选择(供您选择):
Axis2 数据绑定框架 (ADB) 支持类型层次结构和自定义限制。

优点:它生成完整的架构结构并实现每个元素的 getter 和 setter。在每种类型的 setter 上,y 检查模式定义的限制,当要设置的值与限制不匹配时,它会抛出异常(在自己的 set 方法中),并且它支持 StAX 进行序列化/反序列化。

缺点:生成的代码可能有点过于冗长,验证异常的解释性太少,它意味着“简单”(因此对于复杂的类型扩展或限制,您可能会发现一些麻烦),并且它包含一些与 ADB 库的依赖关系(即生成的 bean 实现 org.apache.axis2.databinding.ADBBean 接口)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文