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

Cláudio Margulhano cmargulhano at gmail.com
Wed Oct 18 13:56:45 EDT 2006


Boris,

Thanks a lot.
Very good work your library, congratulations!!!

Best regards,
Cláudio

2006/10/18, Boris Kolpackov <boris at codesynthesis.com>:
>
> 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
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (GNU/Linux)
>
> iQGVAwUBRTY+j8iAKQuuCE8dAQJZTgwAs4VcInA02o7cqZu7t5UDRhqzvyEZRwuc
> mkX1Tnkt5pLE41eiyEAWyyobQH8sBhvQHfk492OWa0UH0aRkTMXMpv+vdQfiRkKX
> 1lUWMcdcDnids15RxlqFFexwTQqWMVQOIOwL1HCkQS0VumD0ZVnv6HT0U5sityWQ
> uYrNKJkQ8t+dQh7xSuNh1r6Fq/4J7BG8jv2dwBRd//kba3+qvWsg1meUvwq8CIp8
> nAKrjOutnl/eqwIVqvHtiIcRFG7d4Am8J6q1kvnrZeszGAIKxvJsQFb6Nby2eZOX
> a3hVbmivMFGHaZi2BMLC4rUoYwj2FKNGa6HT5kI5vAEJF2YzMQUIeKL/nC/89gVV
> 9BqI+ODmdgsbEqC7sCzgol1y8/JrfDiVrJ5dC3SVZCdPJpDqU9aTaNbf1fzdQXf/
> iVx9jWLH1OPSAv6DE3w6ABeXiNfr0YbM+OmTnde19TPKR/pfxiiaogUi6eBBEpnL
> Za1QV7ui/IkfSqkkoohpIb6y0uFP8YKI
> =5b2U
> -----END PGP SIGNATURE-----
>
>
>



More information about the xsd-users mailing list