关于 Jaxb 2.x SchemaGen 的问题
我正在尝试使用 jaxb 从我现有的 POJO 类生成模式,到目前为止它工作正常,现在我有一个要求,我需要声明属性类型是我的 XSD,但属性值应该是预定义值之一。 下面是我的班级的代码快照,
private String destinationID;
private String contactNo;
private String type;
@XmlAttribute
private String name;
我的要求是名称应该包含任何预定义值,与此类似的模式
<xsd:attribute name="type"
type="simpleType.Generic.ProductReferenceType" use="required" />
<xsd:simpleType name="simpleType.Generic.ProductReferenceType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="OFFER" />
<xsd:enumeration value="SELLER" />
<xsd:enumeration value="DEFINITION" />
</xsd:restriction>
</xsd:simpleType>
我无法找出我需要在班级中做什么才能实现这种情况,
提前致谢
i am trying to generate schema using jaxb from my exisitng POJO classes and till now its working fine now i have a requirement where i need to declare a attribute type is my XSD but the attribute value should be one of the predefined values.
below is the code snap shot from my class
private String destinationID;
private String contactNo;
private String type;
@XmlAttribute
private String name;
my requirement is that name should contain any of the predeifned value a schema similar to this
<xsd:attribute name="type"
type="simpleType.Generic.ProductReferenceType" use="required" />
<xsd:simpleType name="simpleType.Generic.ProductReferenceType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="OFFER" />
<xsd:enumeration value="SELLER" />
<xsd:enumeration value="DEFINITION" />
</xsd:restriction>
</xsd:simpleType>
i am unable to find out what things i need to do in my class in order to achieve this case
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样定义一个枚举:
然后只需在您的类中使用它:
这将生成 XSD,如下所示:
祝
您的项目好运!
You can define an enum like this:
and then simply use that in your class:
This will generate XSD as follows:
and
Good luck in your project!