[xsd-users] Problems Accessing Object

Boris Kolpackov boris at codesynthesis.com
Thu Sep 18 12:13:56 EDT 2008


Hi,

D. S. <dsuhpublic at gmail.com> writes:

> My test driver app:
>         auto_ptr<MediaServerControl> msc (MediaServerControl(argv[1]));
>         MediaServerControl::request_optional& reqo (msc->request());
> 
> root element in .xsd:
>      <xs:element name="MediaServerControl">
>        <xs:complexType>
>          <xs:choice>
>            <xs:element name="request">
>              <xs:complexType>
> [...]

What happens here is the following: MediaServerControl is a global
element with anonymous type inside. When the XSD compiler translates
this to C++ it automatically assigns a name to the anonymous type
which is derived from the outer element name. So we end up with
both the type and global element being called MediaServerControl.
Since it is inconvenient in C++ to have both a class and a function
with the same name in the same scope, the XSD compiler renames 
(escapes) the parsing function name in this case by appending '_'
to it (this is explained in more detail in Section 2.1.1, 
"Identifiers" in the C++/Tree Mapping User Manual[1]).

Based on this insight we can change your code like so (note the
underscore in the parsing function call):

auto_ptr<MediaServerControl> msc (MediaServerControl_(argv[1]));
MediaServerControl::request_optional& reqo (msc->request());

if (reqo.present ())
{
  request& r = reqo.get ();

  ...
}

You can also alter the way XSD derives names for anonymous types.
For example, you can append "Type" to every such name. For more
information on how to do this see the documentation for the 
--anonymous-regex command line option in the XSD Compiler Command
Line Manual[2].

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

[2] http://www.codesynthesis.com/projects/xsd/documentation/xsd.xhtml

Boris




More information about the xsd-users mailing list