java - XSD FOR XML element multiple occurrences -


i'm new xsd , want generate xml below studentrecord occurring multiple times. i'm using jaxb generate classes on xsd

<studentdetail>   <studentinformation>     <studentrecord>         <name>abc</name>         <class>4</class>         <major>science</major>         <grade>a</grade>     </studentrecord>     <studentrecord>         <name>def</name>         <class>4</class>         <major>science</major>         <grade>b</grade>     </studentrecord> </studentinformation> 

my current xsd generates studentrecord once.

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns="http://webservice.com/ws" targetnamespace="http://webservice.com/ws" elementformdefault="qualified" attributeformdefault="unqualified"> <xs:element name="student" type="student"/> <xs:complextype name="student">     <xs:sequence>         <xs:element name="studentdetail">             <xs:complextype>                 <xs:sequence>                     <xs:element name="studentinformation">                         <xs:complextype>                             <xs:sequence>                                 <xs:element name="studentrecord">                                     <xs:complextype>                                         <xs:sequence>                                             <xs:element type="xs:string" name="name"/>                                             <xs:element type="xs:string" name="class"/>                                             <xs:element type="xs:string" name="major"/>                                             <xs:element type="xs:string" name="grade"/>                                         </xs:sequence>                                     </xs:complextype>                                 </xs:element>                             </xs:sequence>                         </xs:complextype>                     </xs:element>                 </xs:sequence>             </xs:complextype>         </xs:element>     </xs:sequence> </xs:complextype> 

please fix.

thanks

you need set maxoccurs attribute on studentrecord element declaration, this:

<xs:element name="studentrecord" maxoccurs="unbounded"> 

this allow <studentrecord> appear many times want. default given element required appear once.

similarly, can set minoccurs attribute specify minimal number of occurrences of element.


Comments

Popular posts from this blog

What Are The Best Universities In The World?

Hard vs. Soft Water: What's The Difference?

Why People Get Naked Before Freezing To Death