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

Ellinger (EXT), Klaus ellinger.klaus.ext at siemens.com
Tue Sep 24 10:46:08 EDT 2013


Hello Boris,

Thx for the response. I tried to customize the standard IDREF by using following command line parameter:

--custom-type IDREF=myidref

In the generated schema there is also class definition for myidref, the problem is that in the generated code the default type is used "::xsd::cxx::tree::idref<....>". Can I replace the ootb type by regular expressions?

Best regards

Klaus



-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Dienstag, 24. September 2013 11:49
To: Ellinger (EXT), Klaus
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] Change Id and all IdRef's

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

-----------------
Siemens Industry Software GmbH; Sitz der Gesellschaft: Wolfgang-Pauli-Strasse 2, A-4020 Linz, Österreich
Firmenbuchnummer: FN 214676 a; Firmenbuchgericht: Handelsgericht Linz



More information about the xsd-users mailing list