xsd定义complexType的列表
来源:互联网 发布:网络购物诈骗案例分析 编辑:程序博客网 时间:2024/04/28 03:39
假设有如下结构,node节点下面有一个叫clist的子节点,而子节点下面有一个complexType,它包含name和title两个属性,这里要作为列表返回的就是这个complexType,也就是clist就是保存complexType的List。
用xsd来描述:
<xs:element name="node"> <xs:complexType> <xs:sequence> <xs:element name = "clist" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="title" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType></xs:element>生成列表比较关键的就是把maxOccurs属性设置为unbounded
使用jaxb2插件把xsd文件生成java代码(eclipse和idea都有)
上述文件生成的代码内容如下:
@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name = "", propOrder = { "clist"})@XmlRootElement(name = "node")public class Node { @XmlElement(required = true) protected List<Node.Clist> clist; /** * Gets the value of the clist property. * * <p> * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a <CODE>set</CODE> method for the clist property. * * <p> * For example, to add a new item, do as follows: * <pre> * getClist().add(newItem); * </pre> * * * <p> * Objects of the following type(s) are allowed in the list * {@link Node.Clist } * * */ public List<Node.Clist> getClist() { if (clist == null) { clist = new ArrayList<Node.Clist>(); } return this.clist; } /** * <p>anonymous complex type的 Java 类。 * * <p>以下模式片段指定包含在此类中的预期内容。 * * <pre> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/> * </sequence> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "name", "title" }) public static class Clist { @XmlElement(required = true) protected String name; @XmlElement(required = true) protected String title; /** * 获取name属性的值。 * * @return * possible object is * {@link String } * */ public String getName() { return name; } /** * 设置name属性的值。 * * @param value * allowed object is * {@link String } * */ public void setName(String value) { this.name = value; } /** * 获取title属性的值。 * * @return * possible object is * {@link String } * */ public String getTitle() { return title; } /** * 设置title属性的值。 * * @param value * allowed object is * {@link String } * */ public void setTitle(String value) { this.title = value; } }}
这时我们就可以看到设置了maxOccurs属性为unbounded的clist是作为List定义的。
阅读全文
0 0
- xsd定义complexType的列表
- #XML之路#XSD——complexType
- xsd文件的定义
- simpleType与complexType的区别
- wdsl的complexType中的sequence
- XSD定义
- dataset.xsd的定义(vs2008)
- XSD基础-简易元素的定义
- 拥有complexType的schema生成java代码
- 如何定义Xsd文件
- 如何定义Xsd文件
- 如何定义Xsd文件
- 如何定义Xsd文件
- 如何定义Xsd文件
- 如何定义Xsd文件
- 如何定义Xsd文件
- 如何定义Xsd文件
- 如何定义Xsd文件
- jenkins 构建 Android应用时出现类似“The SDK directory '/root/android-sdk-linux' does not exist.”的解决方案
- [MyBatis]Invalid bound statement (not found)错误解决方法总结
- Axure RP 8 注册码(序列号亲测可用)
- ..
- Hbase_Shell基本操作
- xsd定义complexType的列表
- HyperLPR中文车牌 开源项目使用笔记
- apk自动安装时出现 INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES
- php打印error信息
- 用gcc编译.cpp文件可能出现"undefined reference to `__gxx_personality_v0'"问题
- js ==与===区别(两个等号与三个等号)
- JavaWeb实现QQ第三方登陆
- 用docker+ES+kafka搭建用户行为数据收集系统
- 记录自己的成长—IDEA快捷键