[xsd-users] Problem with duplicate Ids
boris at codesynthesis.com
Mon Dec 26 05:16:04 EST 2005
BURGESS, Mark, FM <Mark.BURGESS at rbos.com> writes:
> I have now created a cut down complete example which exhibits the same
Thanks for doing this. It was very helpful. This problem is an interesting
one. Here is the relevant code snippet:
ExecutionEnvironment executionEnvironment ("ExecutionEnvironment:2");
ExecutionOperation executionOperation ("ExecutionOperation:3",
The second argument to ExecutionOperation's c-tor is of type
xml_schema::ncname. executionEnvironment.id () returns an instance of
the xml_schema::id type. xml_schema::id inherits from xml_schema::ncname.
The problem arises from the fact that all containers in the document
tree are polymorphism-aware . This means that they preserve dynamic
types of objects rather than only static types (like std:: containers
do). Here is what happens in the example above: the second argument
to ExecutionOperation has static type ncname and dynamic type id. The
c-tor implementation uses clone() function to make complete (dynamic)
copy of the object. As a result we end up with another instance of id
which contains "ExecutionEnvironment:2". Later when we try to insert
executionOperation into the tree we end up with the duplicate_id
exception because it conflicts with the executionEnvironment's id.
I agree this is somewhat unexpected in this particular case and I am
thinking of a way to make it less surprising. The fact that XML Schema
allows polymorphic behavior on any type (via xsi:type) will make it
hard to find a good solution to this problem.
A simple workaround for this problem is to pass a temporary of ncname
to ExecutionOperation c-tor, e.g.,
ExecutionOperation executionOperation (
xml_schema::ncname (executionEnvironment.id ()));
Alternatively, you may want to change the type of the ref attribute from
NCName to IDREF.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20051226/c3f9583d/attachment.pgp
More information about the xsd-users