[xsd-users] Binding to referenced objects when using key/keyref

Boris Kolpackov boris at codesynthesis.com
Fri Jun 6 03:21:29 EDT 2008


Hi Nick,

Nick John <Nick.John at ActivIdentity.com> writes:

> Is there a command line option which will cause the creation of code to
> manage key/keyref items similar to that of ID/IDREF ?
> 
> (ie, adding new items will check items for unique key, access keyref
> will provide pointer to item with matching key)

No there is no such mapping at the moment. We thought of creating
something like this, however, there is one problem: the 
key/unqiue/keyref constructs are defined in an element, not in a 
type. As a result, it is not clear where to place the mapping
for them. For local elements we could use the outer type but for
global elements (which are translated to parsing/serialization
functions), it is not clear where to place the mapping. Making it
global does not seem to be a good idea since then the constraint
will be shared across all instances of a document (it is also not
clear how to associate such a global data with instances that are
created programmatically).

Even if we solved this problem, the general-purpose solution would
require a substantial effort since we would need support for mapping
XPath expressions to members in the object model. This gets tricky
very quickly once you start considering optional and sequences of
elements. Overall, this relatively seldom used feature does not
seem to be worth the effort.


> Also, is there any form of ID generation code being created that we have
> overlooked?  For instance to create an ID for a new element we have been
> going to the root node and calling _lookup_id() to ask if the id exists
> until we find one that does not.

No, there is no such support. Normally, IDs have some meaning and are
assigned by the application. Your approach of using _lookup_id() is
fine if a bit slow in case you have a large number of IDs. An
alternative would be to customize the root type of your vocabulary
(or even xml_schema::type) and implement ID generation logic there
using a counter of something along these lines.


Boris




More information about the xsd-users mailing list