[xsde-users] XSD or XSD/e?

Boris Kolpackov boris at codesynthesis.com
Wed Aug 19 08:58:12 EDT 2009


Hi Duncan,

In the future please keep your replies CC'ed to the xsde-users mailing
list. This way other developers who may have experienced a similar
problem can provide you with a solution. Plus questions and answers
will be archived and available to others with similar problems.
See the posting guidelines for more information:

http://www.codesynthesis.com/support/posting-guidelines.xhtml


Duncan.Perrett at elekta.com <Duncan.Perrett at elekta.com> writes:

> Another question on XML Data Binding for you!
> 
> If I have an XML file which contains 200 elements like this ...
> 
> motor1
> motor2
> - -
> - -
> motor200
> 
> Will the serialization result in C++ methods like
> 
> getMotor1()
> getMotor2()
> 
> and
> 
> setMotor1()
> setMotor2() ?
> 
> 
> I assume that it what the CodeSynthesis XSD/e will produce for me.

Yes, something along these lines.


> My problem is that I really would prefer to use a loop in the application, 
> eg
> 
> for (i=0; i<constNumMotors; i++)
> {
>     getMotor(i);
> }
> 
> Otherwise I've got to call getMotor1(), getMotor2() 200 times 
> consecutively!

No, there is no automatic way to get such a custom API. Also note 
that it will only be useful if all your motorN elements are of the
same type. Otherwise, it is not clear what getMotor(i) would return.

If you really need this kind of API and all motor elements are of
the same type, it is easy to write a small (C++) program which will
generated an adapter function, something along these lines:

MotorType getMotor (int i)
{
  switch (i)
  {
  case 1:
    return getMotor1 ();
  case 2:
    return getMotor2 ();

  ...

  case 200:
    return getMotor200 ();
  }
}

Boris



More information about the xsde-users mailing list