[xsd-users] cout problem with hexBinary

Boris Kolpackov boris at codesynthesis.com
Tue Nov 27 14:56:47 EST 2007


Hi Andrew,

Andrew McDonald <Andrew.McDonald at vgt.net> writes:

> Schema file snippet:
>         <xsd:element name="comPortAddress" type="xsd:hexBinary" minOccurs="0" />
>
> Corresponding XML config file:
> 	 <comPortAddress>03F8</comPortAddress>
>
> Source code that breaks:
>         std::cout << "comPortAddress: " <<  sas->comPortAddress() << "\n" ;

Have you compiled your schemas with the --generate-ostream options?
This option triggers generation/inclusion of std::ostream insertion
operators (operator<<) which appear to be missing in your case.

Also note that comPortAddress is optional (minOccurs="0") so you may
want to check whether it is present first:

if (sas->comPortAddress().present ())
{
  std::cout << "comPortAddress: " <<  sas->comPortAddress().get () << "\n" ;
}

or, same as above but using the pointer notation:

if (sas->comPortAddress())
{
  std::cout << "comPortAddress: " <<  *sas->comPortAddress() << "\n" ;
}

For more information on how to access optional (and other kinds of)
elements and attributes, see Chapter 4, "Working with Object Models"
in the C++/Tree Mapping Getting Started Guide:

http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/#4

Boris




More information about the xsd-users mailing list