[xsde-users] Utilizing Inhertied String Classes

Jonathan Haws Jonathan.Haws at sdl.usu.edu
Tue May 22 19:01:18 EDT 2012


I have an XSD that has facets on some attributes.  For example, one attribute is an IP address and it has a facet that forces the value to be a valid IP address.

Here is the XML in the XSD:

    <xs:attribute name="ipaddr">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:pattern
                    value="((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])"
                />
            </xs:restriction>
        </xs:simpleType>
    </xs:attribute>

Various elements reference this attribute.  XSD/e generates code just fine and I can access the value of the IP address, however my problem is in that I cannot figure out how to change it.

For example, if I want to serialize an XML string and add an element that should look like this:

<sensor ipaddr="10.0.0.1" />

I would think all I have to do is this (this assumes that the sensor element is optional and I can have more than one in the XML):

sensor sen;
sen.ipaddr("10.0.0.1");
top->push_back(sen);

This code does not compile because the ipaddr class is declared like this:

  class ipaddr: public ::std::string
  {
    public:
    ipaddr ();
  };

and all the accessor routines for those elements are declared like this:

    // ipaddr
    //
    const ::SMS::ipaddr&
    ipaddr () const;

    ::SMS::ipaddr&
    ipaddr ();

    void
    ipaddr (const ::SMS::ipaddr&);

If I remove the facet, things work just fine, but I would really like to be able to verify that an IP address is valid in my code.

What am I doing wrong?  How can I update the IP address?  I would like to avoid using things like ipaddr.clear() and ipaddr.replace() if at all possible.

Thanks!

Jonathan

--
Jonathan R. Haws
jhaws at sdl.usu.edu




More information about the xsde-users mailing list