[xsd-users] sequence copy and xsd:IDREF

Boris Kolpackov boris at codesynthesis.com
Wed Oct 29 16:44:26 EDT 2008


Hi Sumant,

Sumant Tambe <sutambe at dre.vanderbilt.edu> writes:

> I'm getting a seg-fault while trying to access xsd:IDREF attribute in a 
> *copy* of a sequence. For instance, in the library catalog example, 
> "recommends" is an xsd:IDREF attribute. The following code seg-faults 
> when b is a copy but works fine when it is a reference.
> 
> std::auto_ptr<catalog> c (catalog_ (argv[1]));
> catalog::book_sequence b = c->book();
> 
> for (catalog::book_const_iterator bi (b.begin ());
>      bi != b.end (); ++bi)
> {
>   if (ai->recommends ())
>      cerr << "  Recommends : " << (*ai->recommends ())->title ();
> }
> 
> Why is such a difference in the behavior?

Because when you dereference an IDREF pointer the corresponding 
ID value is searched in the tree that this object is part of.
When you use a reference, the sequence is part of the original
tree and the object with ID in question can be located. When
you make a copy of the sequence, the copy is on its own and 
when you try to dereference an IDREF pointer the corresponding 
ID cannot be found, NULL is returned, and you get a segfault.

Generally, it makes little sense to make copies of parts of the
tree since it wastes resources.

Boris




More information about the xsd-users mailing list