XSD definition for same elements in an XML -


i trying come xsd complex type xml these contents

<simpledata name="omsid">46</simpledata> <simpledata name="registrationnumber">206-tg-4</simpledata>  <simpledata name="obstacletype">antenna</simpledata>   <simpledata name="signature">oei</simpledata> <simpledata name="state">a</simpledata> <simpledata name="maxheightagl">75</simpledata> <simpledata name="topelevationamsl">787</simpledata>  

in example above elements same , each has same name attribute tag different value.

please suggest.

thanks

do want complex type name attribute? if so, how his:

  <element name="simpledata">     <complextype>       <simplecontent>         <extension base="string">           <attribute name="name" type="string" use="required"/>         </extension>       </simplecontent>     </complextype>   </element> 

or want names limited ones used above? if case, try version:

  <element name="simpledata">     <complextype>       <simplecontent>         <extension base="string">           <attribute name="name" type="mydatatypes" use="required"/>         </extension>       </simplecontent>     </complextype>   </element>   <simpletype name="mydatatypes">     <restriction base="string">       <enumeration value="omsid"/>       <enumeration value="registrationnumber"/>       <enumeration value="obstacletype"/>       <enumeration value="signature"/>       <enumeration value="state"/>       <enumeration value="maxheightagl"/>       <enumeration value="topelevationamsl"/>     </restriction>   </simpletype> 

also wasn't clear me question if wanted limits on number of times each element can used? should each of them used ones , in order gave or above samples you?

added new example based on feedback, time restricting attributes each of them present ones.

you'll need test on parent element simpledata, i've called root you can use whatever want.

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" elementformdefault="qualified">   <xs:element name="root">     <xs:complextype>       <xs:sequence>         <xs:element minoccurs="0" maxoccurs="unbounded" ref="simpledata"/>       </xs:sequence>       <xs:assert test="count(simpledata) = 7"/>     </xs:complextype>     <xs:unique name="uniquesimpledata">       <xs:selector xpath="simpledata" />        <xs:field xpath="@name" />      </xs:unique>   </xs:element>   <xs:element name="simpledata">     <xs:complextype>       <xs:simplecontent>         <xs:extension base="xs:string">           <xs:attribute name="name" type="mydatatypes" use="required"/>         </xs:extension>       </xs:simplecontent>     </xs:complextype>   </xs:element>   <xs:simpletype name="mydatatypes">     <xs:restriction base="xs:string">       <xs:enumeration value="omsid"/>       <xs:enumeration value="registrationnumber"/>       <xs:enumeration value="obstacletype"/>       <xs:enumeration value="signature"/>       <xs:enumeration value="state"/>       <xs:enumeration value="maxheightagl"/>       <xs:enumeration value="topelevationamsl"/>     </xs:restriction>   </xs:simpletype> </xs:schema> 

two things new. first assert (this works in xsd 1.1! - please make sure software supports version 1.1 otherwise you'll error message. assert checks have 7 simpledata elements present (one each attribute). second new thing unique constrain, ensures each element attribute combination used ones.

with unique check disallow double entries possible omit 1 list , have 6 of them present, need both of checks.

hope solves problem.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -