xml - What is the proper way in xsd to define a set of elements that may be child elements and may repeat? -


i trying determine proper way using xsd schema define element may contain of set of child elements including possible repeat child elements.

for example, given following xml document:

<?xml version="1.0" encoding="utf-8" ?> <encounterdefinitions   xmlns="http://lavendersoftware.org/schemas/steamgame/data/xml/encounters.xsd">   <encounter name="sample encounter">     <task>       <weapon/>       <weapon/>       <information/>     </task>     <task>       <tool count="3"/>       <ritual/>     </task>   </encounter> </encounterdefinitions> 

i've managed sus out xsd far.

<?xml version="1.0" encoding="utf-8"?> <xs:schema id="encounters"     targetnamespace="http://lavendersoftware.org/schemas/steamgame/data/xml/encounters.xsd"     elementformdefault="qualified"     xmlns="http://lavendersoftware.org/schemas/steamgame/data/xml/encounters.xsd"     xmlns:mstns="http://lavendersoftware.org/schemas/steamgame/data/xml/encounters.xsd"     xmlns:xs="http://www.w3.org/2001/xmlschema" >       <!-- attribute types -->   <xs:attribute name="name"  type="xs:string" />    <!-- complex types -->    <xs:element name="task">     <xs:complextype>       <xs:sequence>         <!-- type here should of set of elements -->         <xs:element name="objective" type="objective"/>       </xs:sequence>     </xs:complextype>     </xs:element>    <xs:element name="encounter">     <xs:complextype>       <xs:sequence>         <xs:element ref="task"/>       </xs:sequence>       <xs:attribute ref="name" use="required"/>     </xs:complextype>   </xs:element>    <xs:element name="encounterdefinitions">     <xs:complextype>       <xs:sequence>         <xs:element ref="encounter"/>       </xs:sequence>     </xs:complextype>   </xs:element> </xs:schema> 

if there no constraints on order of children or number of occurrences of each, use repeating choice:

<xs:complextype>   <xs:choice maxoccurs="unbounded">     <xs:element name="objective" type="objective"/>     <xs:element name="weapon" type="weapon"/>     <xs:element name="information" type="information"/>   </xs:sequence> </xs:complextype> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -