[xsde-users] Utilizing Inhertied String Classes

Ivan Le Lann ivan.lelann at free.fr
Wed May 23 03:50:08 EDT 2012



----- Mail original -----
> De: "Jonathan Haws" <Jonathan.Haws at sdl.usu.edu>
> À: xsde-users at codesynthesis.com
> Envoyé: Mercredi 23 Mai 2012 01:01:18
> Objet: [xsde-users] Utilizing Inhertied String Classes
> 
> 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.
> 

(with xsde-users in cc this time ...)

I'd say:

sen.ipaddr().assign("10.0.0.1");

Regards,
Ivan



More information about the xsde-users mailing list