xml - Can I make a type in xsd to be a choice without the parent element? -


i have 2 types defined in .xsd, ip , ipv6. need have element in .xml file either of 2 types.

to figured might use xsd:choice problem implies parent element, e.g.:

<xs:element name="remote_ip">   <xs:complextype>     <xs:choice>       <xs:element name="remote_ip" type="ip"/>       <xs:element name="remote_ip" type="ipv6"/>     </xs:choice>   </xs:complextype> </xs:element> 

this allows me following in .xml:

<remote_ip>   <remote_ip>10.0.0.1</remote_ip> </remote_ip> 

and need following:

<remote_ip>10.0.0.1</remote_ip> 

ip , ipv6 types definitions:

<xs:simpletype name="ip">   <xs:restriction base="xs:string">    <xs:pattern value="([0-9]*\.){3}[0-9]*" />   </xs:restriction>  </xs:simpletype>  <xs:simpletype name="ipv6">    <xs:annotation>      <xs:documentation>        ip version 6 address, based on rfc 1884.      </xs:documentation>    </xs:annotation>    <xs:restriction base="xs:token">      <!-- specified address -->      <xs:pattern value="[0-9a-fa-f]{1,4}(:[0-9a-fa-f]{1,4}){7}"/>      <!-- double colon start -->      <xs:pattern value=":(:[0-9a-fa-f]{1,4}){1,7}"/>      <!-- double colon middle -->      <xs:pattern value="([0-9a-fa-f]{1,4}:){1,6}(:[0-9a-fa-f]{1,4}){1}"/>      <xs:pattern value="([0-9a-fa-f]{1,4}:){1,5}(:[0-9a-fa-f]{1,4}){1,2}"/>      <xs:pattern value="([0-9a-fa-f]{1,4}:){1,4}(:[0-9a-fa-f]{1,4}){1,3}"/>      <xs:pattern value="([0-9a-fa-f]{1,4}:){1,3}(:[0-9a-fa-f]{1,4}){1,4}"/>      <xs:pattern value="([0-9a-fa-f]{1,4}:){1,2}(:[0-9a-fa-f]{1,4}){1,5}"/>      <xs:pattern value="([0-9a-fa-f]{1,4}:){1}(:[0-9a-fa-f]{1,4}){1,6}"/>      <!-- double colon end -->      <xs:pattern value="([0-9a-fa-f]{1,4}:){1,7}:"/>      <!-- embedded ipv4 addresses -->      <xs:pattern value="((:(:0{1,4}){0,3}(:(0{1,4}|[ff]{4}))?)|(0{1,4}:(:0{1,4}){0,2}(:(0{1,4}|[ff]{4}))?)|((0{1,4}:){2}(:0{1,4})?(:(0{1,4}|[ff]{4}))?)|((0{1,4}:){3}(:(0{1,4}|[ff]{4}))?)|((0{1,4}:){4}(0{1,4}|[ff]{4})?)):(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])"/>      <!-- unspecified address -->      <xs:pattern value="::"/>    </xs:restriction>  </xs:simpletype> 

you want union type here:

<xs:element name="remote_ip" type="ipv4_or_ipv6"/>  <xs:simpletype name="ipv4_or_ipv6">   <xs:union membertypes="ipv4 ipv6"/> </xs:simpletype> 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -