[xsd-users] Help needed - codesynthesis on HP-UX 11.31 with aC++ using xsd:choice

Boris Kolpackov boris at codesynthesis.com
Fri Nov 4 09:34:39 EDT 2011


Hi Abhay,

Bhave, Abhay V <abhave at telcordia.com> writes:

>    <xsd:complexType  name = "GetDetailsResp" >
>      <xsd:sequence>
>             <xsd:choice minOccurs="1" maxOccurs="1" >
>                <xsd:element name = "Work" type = "GetJobWork" minOccurs="1" maxOccurs="1" >
>
> [...]
>
>    <xsd:complexType  name = "GetJobWork" >
>       <xsd:sequence>
> [...]
>       </xsd:sequence>
>    </xsd:complexType>
>
> Using the document and example as a guide my code like below
> 
>     auto_ptr<Job::v1::GetDetailsResp> getDetailsRespPtr(0);
>     getDetailsRespPtr = Job::v1::GetDetailsResp_(argv[1], flags::dont_validate);
>     ( getDetailsRespPtr.get())->Work();
> 
> Question: how do I figure out the type of Work?

I am not sure I understand your question. From the schema you can
see that the Work element is of the GetJobWork type. So there will
be a C++ class Job::v1::GetJobWork.

Also note that in your schema the Work element is inside a choice
compositor. In the C++/Tree mapping this means that the resulting
C++ member will be of the "optional" cardinality. To access such
an element you would need to write something like this:

if (getDetailsRespPtr->Work ().present ())
{
  Job::v1::GetJobWork& w (getDetailsRespPtr->Work ().get ());
}

For more information on different member cardinalities and how to
access them, please read the first two sections in 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