[xsd-users] copying IDREF elements classes

Boris Kolpackov boris at codesynthesis.com
Thu Jun 21 05:16:33 EDT 2012


Hi Omkar,

Omkar Wagh <owagh at tower-research.com> writes:

> Now, if I try to access an even_bigger_unit that points to the say  
> some_bigger_unit with ID="2", then it would run into a problem because
> now there are two some_bigger_units with the same ID within the
> same container and it seg faults.

The ID attribute should be unique in the XML, so this is consistent
with that restriction, except for the seg fault Are you sure it is
not throwing the duplicate_id exception?

In any case, let me tell you how this mechanism work so that you
will be able to answer this kind of questions yourself in the
future (that's the problem with documenting _container() -- it
raises more and more obscure questions unless you know exactly
how it is implemented).

IDREF in C++/Tree doesn't store a pointer to the node it points
to. Rather it stores the value of the ID and whenever you need
the pointed-to node, it does a lookup in the ID-to-node map
that is stored in the root node of the object model. Whenever
a node is added somewhere in the model, its _container()
function is called to notify it that it is now part of that model.
In _container() the node registers all its IDs in the map. If
there is a duplicate, then you get the duplicate_id exception.


> I suppose if there now were a way to "unset" the container once the job  
> of the temporary is done, that too might work.

Yes, you can do that by passing NULL pointer to _container(). That's
what happens when you detach a node from a model.

Boris



More information about the xsd-users mailing list