[xsde-users] Unexpected Element Encountered
Boris Kolpackov
boris at codesynthesis.com
Mon Nov 16 12:27:12 EST 2009
Hi Tony,
Tony McConnell <amnw14545 at googlemail.com> writes:
> I'm having a problem trying to get a test parser and test
> implementation working with xsde.
>
> I'm using xsde 3.1.0, and performing the following steps:
>
> xsde cxx-parser --force-overwrite --generate-polymorphic
> --disable-warning all --generate-print-impl --generate-test-driver
> --namespace-map http://datex2.eu/schema/1_0/1_0=datex2
> DATEXIISchema_1_0_1_0.xsd
>
> [...]
>
> I'm using the MeasuredDataWeatherData.xml from the example messages.
>
> I'm expecting the example implementation to read the entire file and
> print out the contents, but it aborts with the following message:
> MeasuredDataWeatherData.xml:16:33: unexpected element encountered.
This due to the use of polymorphism in this schema. While the generated
parsers are polymorphism-aware, the generated sample driver is not. In
other words, it does not create the parser maps with all the possible
derivations and does not pass true to document_pimpl's c-tor to indicate
polymorphic parsing. As a result, the content for the payloadPublication
is parsed as the base PayloadPublication type instead of the derived
MeasuredDataPublication type which is specified with the xsi:type
attribute.
You can fix the generated sample driver by creating the necessary
maps, for example:
datex2::MeasuredDataPublication mdp_p;
mdp_p.parsers (....);
xml_schema::parser_map_impl payloadPublication_map (7); // 7 hash buckets
map.insert (mdp_p);
D2LogicalModel_p.payloadPublication_parser (payloadPublication_map);
And passing true as the last argument to document_pimpl's c-tor.
You may also want to consider using the C++/Hybrid mapping. It is based
on C++/Parser and builds the in-memory representation of the XML data.
C++/Hybrid will handle polymorphism automatically if you let it know
which types are the bases of polymorphic hierarchies (that is, use
something like --polymorphic-type PayloadPublication).
Also, you could use the parser instantiation and construction code
generated by C++/Hybrid in your C++/Parser-based application if you
don't feel like doing it manually (for this schema it is quite a bit
of code). I tried this and the resulting driver implementation
parses the sample document without any problems. You can download
it here:
http://www.codesynthesis.com/~boris/tmp/DATEXIISchema_1_0_1_0-pdriver.cxx
Boris
More information about the xsde-users
mailing list