[xsd-users] Re: lid_test, no regression test

Boris Kolpackov boris at codesynthesis.com
Sat Oct 29 09:42:34 EDT 2005


Frederic,

I've CC'ed the mailing list to allow others to benefit from this
information.

frederic heem <frederic.heem at telsey.it> writes:

> Another problem has been found, the attibute value of lidLine are
> incorrect, they are all equal to 1. Compare the content of the
> lid_conf.xml anf the output of the program to verify.

In your definition of LidLine type, both attributes are optional:

<xsd:complexType name="LidLine">
  <xsd:attribute name="port" type="xsd:unsignedInt"/>
  <xsd:attribute name="name" type="xsd:string"/>
</xsd:complexType>

This means that when you call LidLine::port or LidLine::name you get
a container, not the object itself. So when you wrote:

cout << "port number = " << lidLineIt->port() << endl;
cout << "port name = " << lidLineIt->name() << endl;

You were actually trying to print the container, not the object
itself. The container for optional elements/attributes (cardinality 0..1)
happened to have implicit conversion to bool (so that it can be used
inside if () statements, etc.). Therefore what you are printing above
is the true/false value which indicated whether the port/name has
been specified. Try to change it to something like this:

if (lidLineIt->port())
  cout << "port number = " << *lidLineIt->port() << endl;

if (lidLineIt->name())
  cout << "port name = " << *lidLineIt->name() << endl;

Alternatively, you can make the attributes mandatory:

<xsd:complexType name="LidLine">
  <xsd:attribute name="port" type="xsd:unsignedInt" use="required"/>
  <xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>

In the next version of xsd I will overload operator<< for the optional
container so that it will print the object if it is set and something
like "<not present>" if not. Hopefully it will be less confusing.


hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20051029/5cd8a7ca/attachment.pgp


More information about the xsd-users mailing list