Java 对象的 XML 模式定义 (XSD) 中的继承
我需要创建一个描述 Java 对象的 XML 模式定义 (XSD)。
我想知道当相关对象继承自具有类型参数的公共基类时如何执行此操作。
public abstract class Rule<T> { ... }
public abstract class TimeRule extends Rule<XTime> { ... }
public abstract class LocationRule extends Rule<Location> { ... }
public abstract class IntRule extends Rule<Integer> { ... }
....
(其中 XTime
和 Location
是在其他地方定义的自定义类)
我将如何构建一个 XSD,以便我可以拥有代表 规则
- 没有每个人的 XSD 重复其共同内容?
谢谢你!
I need to create an XML schema definition (XSD) that describes Java objects.
I was wondering how to do this when the objects in question inherit from a common base class with a type parameter.
public abstract class Rule<T> { ... }
public abstract class TimeRule extends Rule<XTime> { ... }
public abstract class LocationRule extends Rule<Location> { ... }
public abstract class IntRule extends Rule<Integer> { ... }
....
(where XTime
and Location
are custom classes defined elsewhere)
How would I go about constructing an XSD that such that I can have XML nodes that represent each of the subclasses of Rule<T>
- without the XSD for each of them repeating their common contents?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Conisder JAXB for XML Schema -> Java编译。
XML Schema 为继承建模提供了一些可能性:
但是,我认为您无法准确地实现您发布的 Java 代码。不过,您可以使用继承插件。
Conisder JAXB for XML Schema -> Java compilation.
XML Schema gives some possibilities for modelling iheritance:
However, I don't think you can achieve exactly the Java code you're posting. You can, nevertheless get somewhat close with the inheritance plugin.