[xsd-users] Re: Help me please - CodeSynthesis XSD

Boris Kolpackov boris at codesynthesis.com
Wed Oct 18 10:47:43 EDT 2006


Cláudio,

In the future please send technical questions like this to the
xsd-users mailing list (which I've CC'ed) instead of to me directly.
This way a) other developers who may have experienced a similar
problem can provide you with a solution b) questions and answers
will be archived and available to others with similar problems.

Cláudio Margulhano <cmargulhano at gmail.com> writes:


> I'm try to use CodeSynthesis XSD in my application to read a XML file but
> with no sucess.
> Can you help me, please?
> This code allways prints the value 1 at console. What's wrong?
>
>    std::auto_ptr<config_type> c (config (argv[1]));
>    for (config_type::module::const_iterator i (c->module ().begin ()); i !=
> c->module ().end (); ++i)
>    {
>        cerr << i->name() << endl;
>    }
>
> ...
>
>  <xsd:complexType name="module_type">
>        <xsd:sequence>
>        	<xsd:element name="key" type="key_type" maxOccurs="unbounded" minOccurs="1"></xsd:element>
>        </xsd:sequence>
>        <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>  </xsd:complexType>


The 'name' attribute in 'module_type' is optional. As a result XSD-generated
code returns a container for it instead of the object itself (since it may
or may not be present). You can read more about this in the Section 2.8.2,
"Mapping for Members with the Optional Cardinality Class" of the C++/Tree
mapping manual[1].

To fix this your code you can do two things:

1. Make the 'name' attribute required (add the use="required" attribute).
   This is probably a good idea in your situation.

2. Change your code to test for presence and extract the actual value:

if (i->name ().present ())
  cerr << i->name ().get () << endl;



[1] http://codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.8.2

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/20061018/bbd85d90/attachment.pgp


More information about the xsd-users mailing list