[xsd-users] Integrating XSD generated classes into an existing C++ project

Russ Loucks rjl at third-monday.com
Wed Feb 9 10:37:15 EST 2011


On 02/08/2011 01:06 PM, shubhgd at cs.vt.edu wrote:
> Hi,
>
> I am trying to integrate XSD generated classes into an existing C++ 
> project, however, am not able to find the best way to do this. What I 
> did and what I am looking for follows,
> 1. Created C++ classes (cxx and hxx) from an XML schema using xsd 
> cxx-tree.
> 2. Need to include the classes generated in step 1 into an existing 
> C++ make project (it is a huge application with lot of dependencies 
> and all)
> 3. Tried to include the xsd generated classes as #include in the 
> main.cpp of the existing application, but got a lot of runtime errors 
> with error messages like
> ?DOMNode? declared as a ?virtual? field     at external location: 
> /usr/include/xsd/cxx/tree/elements.hxx
>  expected a type, got ?map?                external location: 
> /usr/include/xsd/cxx/tree/elements.hxx
> and so on.
> 4. Not sure how to integrate the two projects (XSD and the existing 
> application) seemingly.
>
> Please let me know if any one has encountered such a problem or has a 
> clue on moving ahead with this. I might be doing something wrong 
> fundamentally, as have no experience in dealing with C++ projects. I 
> appreciate any kind of help. Thank you.
I've been sort of successful doing this sort of thing.  My application 
is not that large, only about 10 or so subdirectories of source files.  
The project is a Qt-based beast and I let that build the Makefiles from 
the Qt project files.

I have a separate (pre-built) Makefile that converts the XSD files to 
source files and builds up a Qt project file for those files.  I do run 
that Makefile separately from the main Qt-based build process;  I just 
haven't figured out how to include that step in the Qt-based project 
build process (e.g., the current process is not painful enough for me to 
change it, yet...).

The directory structure in summary:

root
    src
       dir1
          cpp and h files
       dir2
          cpp and h files
       dir3
          cpp and h files
       xsd
    resource.xsd
<myXSDfiles>

    Makefile.XSD
       This makefile runs xsd-tree over the XSD files in
       'resource.xsd' and puts them in 'src/xsd'.  It then
       creates a 'xsd.pri' (Qt-project include file) of these
       files and puts that in the 'src/xsd' directory.

Other notes:

1) All Makefiles include the Xerces and XSD installation directories in 
the includes options (e.g., -I/usr/share/xsd-3.3.0/libxsd 
-I/usr/share/xerces-c-3/include).

2) All (of my) include files that use XSD-based structures include 
statements to forward declare the classes (since I have namespaces in my 
XSD structures):

namespace model { namespace flowDesign {
     class displayLayoutPanelType;
     class displayLayoutComponentType;
} }
using namespace model::flowDesign;

3) All (of my) source files that use the XSD-based structures include 
the top-level (e.g. root) elements as needed:

#include "xsd/displayLayoutPanelType.h"

4) The Makefiles include the Xerces library path 
(-L/usr/share/xerces-c-3 -lxerces-c_3) to build/link.

Hope that helps.
r

-- 
Russ Loucks
mailto: rjl AT third-monday DOT com
mobile: 612.205.9171
www.third-monday.com



More information about the xsd-users mailing list