[xsd-users] issue creating document in memory

Russ Johns johns at lanl.gov
Mon Jan 8 15:33:55 EST 2007


Hi-

  I am trying to create a prototype app that creates an XML file from an in 
memory representation that is built up from scratch.
After getting a empty root element,  I get a access violation when I try to 
access the first sub element (minOccurs=maxOccurs=1)
The cxx-tree classes were created by xsd with the --generate-serialization 
and --generate-default-ctor options.

  the main routine  up to the point of error:

// SwordMemXml.cpp : Main function declaration, for test application that 
creates in memory representation .
//                   then serializes that to xml.

#include "SWORD-input.hpp"
#include <memory>
#include <iostream>
#include <fstream>
using std::cerr;
using std::endl;
using std::auto_ptr;

int main(int argc, char* argv[])
{
         try {
         // create SwordInput object
                 auto_ptr<SWORD::input::SwordInput> si (new 
SWORD::input::SwordInput());

                 // get element list
                 SWORD::input::ElementList el (si->elementlist());

  the code compiles,  appears to create a SwordInput object,  then gives a 
access violation in auto_ptr<>::get() apparently while trying to 
dereference the si variable to obtain the element list.

Is this how one would typically build up a representation?
I am using MS VS2005 and the latest stable xsd & xerces libs from the 
codesynthesis website.

I have done the same thing using the hello example problem,  but this 
problem seems to perform differently.

  the XML schema portions related to this are below.  I have also been able 
to round trip the XML file I am trying to create in a seperate executable. 
(XML->C++->XML)

Any suggestions as to how to fix the problem?

-Russ Johns

root element:
         <xs:element name="SWORD_input" type="SwordInput"/>
type is:
         <xs:complexType name="SwordInput">
                 <xs:sequence>
                         <xs:element name="elementlist" type="ElementList"/>
                         <xs:element name="materiallist" type="MaterialList"/>
                         <xs:element name="objectlist" type="ObjectList"/>
                         <xs:element name="rotationlist" type="RotationList"/>
                         <xs:element name="volumelist" type="VolumeList"/>
                         <xs:element name="world_positions" 
type="WorldPositions"/>
                         <xs:element name="energies" type="Energies"/>
                         <xs:element name="runinfo" type="RunInfo"/>
                 </xs:sequence>
         </xs:complexType>

where ElementList is defined as:
         <xs:complexType name="ElementList">
                 <xs:choice maxOccurs="unbounded">
                         <xs:element name="isotope" type="Isotope"/>
                         <xs:element name="element" type="Element"/>
                 </xs:choice>
         </xs:complexType>






More information about the xsd-users mailing list