[xsd-users] Problems Accessing Object

D. S. dsuhpublic at gmail.com
Thu Sep 18 14:39:44 EDT 2008


Boris,

I got the code to compile with your change, but the parser fails
("error : Unknown element 'MediaServerControl'" and many others) with
an input xml file if I don't have
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="hello.xsd
Is there a setting or change I can make to use just
<MediaServerControl version="1.0"> ?
The thing is that XSD/e accepts the .xsd and .xml file as it is and
parses and prints out the elements.


<?xml version="1.0"?>

<MediaServerControl version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="hello.xsd">

  <request>

    <play id="332985001">

      <prompt stoponerror="yes"

        baseurl="file:////var/mediaserver/prompts/"

        locale="en_US" offset="0" gain="0" rate="0"

        delay="0" duration="infinite" repeat="1">

        <audio url="num_dialed.raw" encoding="ulaw"/>

        <variable type="dig" subtype="ndn" value="3014170700"/>

        <audio url="num_invalid.wav"/>

        <audio url="please_check.wav"/>

      </prompt>

    </play>

  </request>

</MediaServerControl>



On Thu, Sep 18, 2008 at 9:13 AM, Boris Kolpackov
<boris at codesynthesis.com> wrote:
>
> 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