[xsd-users] Sort of XML "reflection"
Boris Kolpackov
boris at codesynthesis.com
Wed Nov 18 10:02:57 EST 2009
Hi Patrick,
Paquette, Patrick <PaquetP at navcanada.ca> writes:
> I'm trying to think of the best way to do this, any input would be
> appreciated.
>
> I have a complex type T which has a sequence of elements, each of which
> have any cardinality. I know that each of these elements are an
> extension of a base type B.
>
> As an argument, a caller will be passing a string representing the name
> of one of these elements of the complex type T. I'd like to determine
> if such an element exists, and if it does, get a reference to all
> occurences of them to a sequence of B&
>
> I do not have the DOM association yet, as the object type was created
> programatically, to be serialized later.
>
> Short of serializing to a DOMDocument, parsing it to a new instance of
> T, and navigating the DOM tree, is there a better way of doing this?
If this is just one type T and one type B (or, maybe a few such types,
as opposed to the whole object model), then you can customize T to
contain a multimap of, say, element names to instances and customize
B to register on its container. In case of B, the container node is
specified in via c-tors or via the virtual _container() function
(defined in xml_schema::type). You will need to override it to do the
registration. The only issue with this approach is that B (or T) would
need to know the element name in order to register on T. One way to do
this would be to have a static map of std::type_info to element name
in T which is manually populated with all the derivations of B and
their element names (assuming each type is used for one element name).
We will actually need something similar in order to support native XPath/
XQuery execution on the object model. In fact, once it is implemented,
you could use use one of these languages to implement this. But this
is still some time away (a month or two).
Boris
More information about the xsd-users
mailing list