[xsd-users] Change Id and all IdRef's

Boris Kolpackov boris at codesynthesis.com
Tue Sep 24 05:49:01 EDT 2013


Hi Klaus,

Ellinger (EXT), Klaus <ellinger.klaus.ext at siemens.com> writes:

> I have a requirement and I am not sure how to solve it, hopefully you can
> give me an hint if and how it's possible. I have an xsd schema defined with
> ID and IDREF types. In some cases I have to replace some Id's after
> processing so I need to update all IDREF's too to get a valid XML file
> out. I studied the code of ID and IDREF as far I could and mentioned that
> both classes are subtypes of "xsd::string" and the id value will not be
> updated on change. Do you see a solution to update all IDREFS if an ID
> changes?

Conceptually, changing ID is a bad idea exactly for this reason --
all the places that assumed the ID is immutable have to now be 
updated. So instead of changing the ID, consider removing this
requirements at the "allocation logic" level. For example, maybe
you can replace a "full" element that has the ID that you need
to change with a special "forwarding" element that specifies
both the old ID and the ID of the new "full" element.

If you still need to change the ID and somehow update all the
IDREFs that point to it, I am afraid there is no easy way. The
best I could think of would be to customize both the ID and IDREF
types (see the custom/calendar example for how to customize a
built-in type) so that IDREF instances register on the IDs that
they point to and ID instances contain a set of all the IDREFs
that point to them. You will also have to deal with forward
references (i.e., referenced ID hasn't been seen yet) so maybe
it is actually better to have one map in the root of the object
model (that's how the IDREF-to-ID resolution works now). I am
sure this can be done, it is just not going to be easy.

Boris



More information about the xsd-users mailing list