[xsd-users] xml_schema::parser_map usage?

Boris Kolpackov boris at codesynthesis.com
Fri Jun 13 03:08:47 EDT 2008


Hi Pontus,

Pontus Åström <Pontus.Astrom at csr.com> writes:

> I'm looking for a clue of how to use the xml_schema::parser_map
> stuff for parsers with polymorphic types but can't find any
> information.

parser_map is an interface for resolving parsers based on a type
id (you can find its definition in libxsd/xsd/cxx/parser/map.hxx)
Implementations of this interface can be passed instead of an
individual parser to the parser construction functions. You
can provide your own implementation or you can use the default
one provided by the XSD runtime (not currently aliased in
xml_schema, but will be in the next release).

Based on the example in Section 5.4, "Support for Polymorphism"
in C++/Parser Mapping Getting Started Guide you can rewrite this
fragment which does not use parser_map:

  instance_p.person_parser (person_p);
  instance_p.person_parser (superman_p);
  instance_p.person_parser (batman_p);


With something like this:

  xsd::cxx::parser::parser_map_impl<char> person_map_impl;

  person_map.insert (person_p._dynamic_type (), person_p);
  person_map.insert (superman_p._dynamic_type (), superman_p);
  person_map.insert (batman_p._dynamic_type (), batman_p);

  instance_p.person_parser (person_map);

One reason to use a parser map over setting individual parsers
is in the case where you have several places where, say, the
person element can be present in the vocabulary. In this case
it is easier to create and fill the map once and pass it to
those places.


> Is there a document or code snippet somewhere that gives some
> insight? 

We will expand Section 5.4, "Support for Polymorphism" for the
next release with this information. Thanks for the suggestion!


Boris




More information about the xsd-users mailing list