[xsd-users] SWIG output from xsd

Boris Kolpackov boris at codesynthesis.com
Thu Feb 12 13:06:11 EST 2009


Hi Daniel,

Macumber, Daniel <Daniel.Macumber at nrel.gov> writes:

> Hello, I am wondering if there has been any effort to write SWIG
> interface files when writing out the auto generated C++ classes using
> the cxx-tree option of xsd.  Doing this would allow the generated code
> to be used with C#, Ruby, Python, etc.  Have there been any efforts
> towards this approach?  Would it be feasible to try to do this?

Using SWIG to provide XML data binding to scripting languages has
been on our "potential future directions" list for some time now.
There was also a discussion recently which mentioned SWIG in the
context of providing access to C++/Tree object model from C#. So
there is definitely some interest in this:

http://www.codesynthesis.com/pipermail/xsd-users/2009-January/002155.html

At this point, however, it is not clear whether it will be possible
to "wrap" the generated code using SWIG. The C++/Tree object model
is quite complex and I am having a hard time understanding how some
more advanced techniques, for example support for polymorphism, will
be handled. Though, even without support for these techniques (at
least initially) the integration can be useful to quite a few people.
Also SWIG seems to provide a fairly complete support for C++. The only
things that is not supported is nested classes but that is not used
in the generated code.

Another unclear point is whether it will be possible to generate
a single SWIG interface that can be used to generate wrappers for
all possible target languages. If we have to generate some specific
code for C#, Python, etc., then the approach looks a lot less 
attractive.

But we would definitely be interested and provide assistance if you
(or someone else) would like to take a stab at this. The first step
should probably be a hand-written proof-of-concept SWIG interface
for a simple schema that uses the most common features. Something
along these lines:

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:t="test"
        targetNamespace="test">

  <complexType name="Foo">
    <sequence>
      <element name="a" type="int"/>
    </sequence>
  </complexType>

  <complexType name="Bar">
    <complexContent>
      <extension base="t:Foo">
        <sequence>
          <element name="b" type="string" minOccurs="0"/>
        </sequence>
      </extension>
    </complexContent>
  </complexType>

  <complexType name="Baz">
    <sequence>
      <element name="bar" type="t:Bar" maxOccurs="unbounded"/>
    </sequence>
  </complexType>

  <element name="root" type="t:Baz"/>

</schema>

Here you would need to instantiate the xml_schema::string template
as well as container classes for Bar::b and Baz::bar (I wonder how
the typedef names inside Bar and Baz are translated to other
languages).

Boris




More information about the xsd-users mailing list