[xsd-users] Schemas defined across multiple DLLs and the static factory map instance

Matthew.Hutchins at csiro.au Matthew.Hutchins at csiro.au
Mon Jun 16 20:15:42 EDT 2008


Hi,

This email is related to an issue discussed on the list in Oct 2006 on
static variable initialisation, but slightly different.

I am using XSD 3.1 on Windows with Visual Studio 2003 (7).

I am defining a C++ class library hierarchy with some base classes in
one library (A) and some instances in other libraries (B,C,D). Schemas
are defined across all the libraries. The code that reads XML documents
is in library A.
There are schemas defined in B,C,D with elements that are extensions of
those defined in A. Each library is linked into a DLL.

The issue is that the XML reader in library A does not recognise the
subclasses/elements from the other libraries.

The reason is that each DLL has its own unique instance of the static
type_factory_map instance, so the elements from A are added to the
factory map for A, the elements for B are added to the factory map for
B, and so on.

There is a fix for this, but a change to the definition of
type_factory_map would make it easier.

Code linked into each DLL can get access to the factory map instance for
its own DLL like this:

   return ::xsd::cxx::tree::type_factory_map_instance< 0, char > ();

Thus, a base class in library A can expose the factory map instance for
the A DLL, and classes in the other libraries can then see it. The
register_element method can be used to manually add definitions.

What would make this easier is if there was a public method defined in
type_factory_map to add all the elements defined in another
type_factory_map. Then a class in DLL B could get its local factory map
instance and add the definitions to the factory map instance from DLL A.
Perhaps something like this (this is just written in this email, I
haven't compiled or tested it):

public:
void
register_elements(const type_factory_map & that)
{
  for (element_map::const_iterator i = that.element_map.begin(); i !=
that.element_map.end(); ++i)
  {
    for (element_map::const_iterator j = i->second.begin(); j !=
i->second.end(); ++j)
    {
      element_map_[i->first][j->first] = j->second;
    }  
  }
}



Matthew


__________________________________
Dr Matthew A Hutchins
Senior Research Scientist
Networking Technologies Laboratory
CSIRO ICT Centre
---
Matthew.Hutchins at csiro.au
Phone: +61 2 6216 7088 | Mobile: 0408 862 669 | Fax: +61 2 6216 7111
Mail: GPO Box 664 Canberra ACT 2601 Australia
www.ict.csiro.au






More information about the xsd-users mailing list