[xsd-users] Keep a xsd library small
Boris Kolpackov
boris at codesynthesis.com
Mon Apr 27 06:38:01 EDT 2009
Hi Angelo,
Angelo Difino <angelo at cedeo.net> writes:
> Hi Boris and all,
> I still keep working hard on the xsd-types of the schemes i've sent you
> on the 12nd of February.
>
> I've some troubles since in the first release i forgot (me damn it! ;) )
> to include the specifier "--generate-wildcard"
> since i've several tags include the any-type. for example the DIDL.xsd
> include an any tag for the structured data
> type:
>
> didl.xsd -> StatementType -> <element ref="didl-msx:Metadata"/>
> didl-msx -> MetadataType -> StructuredDataType ->
> <sequence>
> <any namespace="##any" processContents="lax" minOccurs="0"/>
> </sequence>
>
> when i need to simply assign (clone) an ItemType (that include the above
> structured data type)
> i've a run-time xerces error on the wildcard-source.txx:
>
> // Get an implementation of the Load-Store (LS) interface.
> //
> xercesc::DOMImplementation* impl (
> xercesc::DOMImplementationRegistry::getDOMImplementation (ls));
>
> return xml::dom::auto_ptr<xercesc::DOMDocument> (
> impl->createDocument ());
>
> Am I missing somethins ? I'm checking your documentation but i really
> wondering if now (that i've added the
> "--generate-wildcard"), i need to implement / wrote some code some where
> to "help" xerces when it founds an any type...
You need to initialize the Xerces-C++ runtime. From Section 2.12, "Mapping
for any and anyAttribute" in the C++/Tree Mapping User Manual:
"For the XML Schema any and anyAttribute wildcards an optional mapping
can be requested with the --generate-wildcard option. The mapping
represents the content matched by wildcards as DOM fragments. Because
the DOM API is used to access such content, the Xerces-C++ runtime
should be initialized by the application prior to parsing and should
remain initialized for the lifetime of objects with the wildcard
content. For more information on the Xerces-C++ runtime initialization
see Section 3.1, "Initializing the Xerces-C++ Runtime"."
> The code that throw the error is:
>
> std::auto_ptr< DIDLType > tmp = DIDL(filename.c_str() , (validate ? 0 :
> xml_schema::flags::dont_validate) );
> mxm_dataobject::schema::didl::ItemType& topelement =
> dynamic_cast<mxm_dataobject::schema::didl::ItemType&>(_didl->Item());
> mxm_dataobject::schema::didl::ItemType secondelement=topelement; (in
> a inner class)
The above code should be something along these lines:
#include <xercesc/util/PlatformUtils.hpp>
int
main ()
{
xercesc::XMLPlatformUtils::Initialize ();
{
std::auto_ptr< DIDLType > tmp = DIDL(filename.c_str(), (validate ? 0 :
xml_schema::flags::dont_validate | xml_schema::flags::dont_initialize) );
mxm_dataobject::schema::didl::ItemType& topelement =
dynamic_cast<mxm_dataobject::schema::didl::ItemType&>(_didl->Item());
mxm_dataobject::schema::didl::ItemType secondelement=topelement;
}
xercesc::XMLPlatformUtils::Terminate ();
}
Notice that I've added the dont_initialize flag to the parsing function
call.
Boris
More information about the xsd-users
mailing list