W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > October to December 2005

1.1 Datatypes - suggest base types for IP addresses

From: Thomson, Martin <Martin.Thomson@andrew.com>
Date: 05 Dec 2005 15:59:02 -0700
Message-ID: <AF9FCF3C02DB264EAF9872DFB6040FCC0C562C42@aopex5.andrew.com>
To: <www-xml-schema-comments@w3.org>


To save us all from having to do something like the below, it might be useful to have an IP address base type.

Constraining facets might be: length, minLength, maxLength, pattern and enumeration.

Care should be taken to ensure that "::1" and "0:0:0:0:0:0:1" are equal.

Values are totally ordered.  Values are bounded (to 32 and 128 bits).

Cheers,
Martin

p.s. maybe someone has a better regex set for IPv6 addresses, I've kept it in different patterns here, but a (...|..|.) set would work equally well.
-----------

  <xsd:simpleType name="ipv4">
    <xsd:annotation>
      <xsd:documentation>
        An IP version 4 address.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:token">
      <xsd:pattern value="(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])"/>
      <xsd:pattern value="[0-9A-Fa-f]{8}"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="ipv6">
    <xsd:annotation>
      <xsd:documentation>
        An IP version 6 address, based on RFC 1884.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:token">
      <!-- Fully specified address -->
      <xsd:pattern value="[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){7}"/>
      <!-- Double colon start -->
      <xsd:pattern value=":(:[0-9A-Fa-f]{1,4}){1,7}"/>
      <!-- Double colon middle -->
      <xsd:pattern value="([0-9A-Fa-f]{1,4}:){1,6}(:[0-9A-Fa-f]{1,4}){1}"/>
      <xsd:pattern value="([0-9A-Fa-f]{1,4}:){1,5}(:[0-9A-Fa-f]{1,4}){1,2}"/>
      <xsd:pattern value="([0-9A-Fa-f]{1,4}:){1,4}(:[0-9A-Fa-f]{1,4}){1,3}"/>
      <xsd:pattern value="([0-9A-Fa-f]{1,4}:){1,3}(:[0-9A-Fa-f]{1,4}){1,4}"/>
      <xsd:pattern value="([0-9A-Fa-f]{1,4}:){1,2}(:[0-9A-Fa-f]{1,4}){1,5}"/>
      <xsd:pattern value="([0-9A-Fa-f]{1,4}:){1}(:[0-9A-Fa-f]{1,4}){1,6}"/>
      <!-- Double colon end -->
      <xsd:pattern value="([0-9A-Fa-f]{1,4}:){1,7}:"/>
      <!-- Embedded IPv4 addresses -->
      <xsd: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])"/>
      <!-- The unspecified address -->
      <xsd:pattern value="::"/>
    </xsd:restriction>
  </xsd:simpleType>

------------------------------------------------------------------------------------------------
This message is for the designated recipient only and may
contain privileged, proprietary, or otherwise private information.  
If you have received it in error, please notify the sender
immediately and delete the original.  Any unauthorized use of
this email is prohibited.
------------------------------------------------------------------------------------------------
[mf2]
Received on Monday, 5 December 2005 23:01:24 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 6 December 2009 18:13:10 GMT