Réf. : Re: [xsd-users] help about XSD

jerome.martinet at mpsa.com jerome.martinet at mpsa.com
Thu Jun 28 07:21:24 EDT 2007


 Hi,

My project is now finish , thanks for you help  (my metamodel was too
difficult I think for a first project with your software but with a lot of
effort I reach my goal). I can rebuild the XML (elements I need) with the
code.
Now I have to explain what I  have done !  That's why I'm looking
explanations : how , with xerces help , the util can build c++ code.
Have you some informations to help me ? I'm looking for diagramms for
example on theory. I haven't found any on your website


thanks

Jérôme



                                                                           
             Boris Kolpackov                                               
             <boris at codesynth                                              
             esis.com>                                                Pour 
                                       jerome.martinet at mpsa.com            
             11/06/2007 16:30                                           cc 
                                       xsd-users at codesynthesis.com         
                                                                     Objet 
                                       Re: [xsd-users] help about XSD      
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Hi Jérôme,

jerome.martinet at mpsa.com <jerome.martinet at mpsa.com> writes:

> I'm working on a project named Autosar. I have the XSD file (which you
can
> find here :http://autosar.org/download/AUTOSAR_xsd.zip) and I want to
> generate C++ code using your tools XSD with Visual studio 2005 express.

Uh, quite a big schema.

>
> I generated the code but I can't access to elements I need
> (ATOMiC-SOFTWARE-COMPONENT for example)
>
> I have a constructor on the class AUTOSAR but nothing on ELEMENTS , how
can
> I use a link between this two elements ?

The root element of your vocabulary is element AUTOSAR and its type is
AUTOSAR. So you get an instance of this type AUTOSAR when you parse
you XML document, e.g.,

using namespace NS_AUTOSAR;

std::auto_ptr<AUTOSAR> autosar (AUTOSAR_ ("autosar.xml"));

Looking at the definition of type AUTOSAR in the schema we see that
its content is defined as a reference to a group (xsd:group) named
AUTOSAR. When a group is referenced somewhere in the schema it is as
if the contents of the group were copied to the place of reference.
So we look at the AUTOSAR group and see that it contains a single
optional (minOccurs="0") element TOP-LEVEL-PACKAGES. Since this
element is optional, the generated code will follow the rules for
the optional cardinality class as described in the manual. So we can
test for presence of this element and get its content like so:

if (autosar->TOP_LEVEL_PACKAGES ().present ())
{
  TOP_LEVEL_PACKAGES& tlp = autosar->TOP_LEVEL_PACKAGES ().get ();


Looking at the type for TOP-LEVEL-PACKAGES we see that it is a
sequence of AR-PACKAGE elements of type AR-PACKAGE. To iterate
over them we can do this:

  TOP_LEVEL_PACKAGES::AR_PACKAGE::container& c = tlp.AR_PACKAGE ();

  for (TOP_LEVEL_PACKAGES::AR_PACKAGE::iterator i (c.begin ());
       i != c.end ();
       ++i)
  {
    AR_PACKAGE& arp = *i;
  }
}

Next you can figure out the contents of AR_PACKAGE, etc. You can also
look into the generated header file to figure out to which cardinality
class a particular element belongs if it is not immediately obvious from
studying the schema.


hth,
-boris
[rattachement "signature.asc" supprimé par JEROME MARTINET -
U278752/users/PSA]





More information about the xsd-users mailing list