views:

313

answers:

2

I'm interested in how people use this feature: what domain, what relationships (apologies if survey questions aren't appropriate).

XML represents trees naturally using containment; but it can also represent graphs, using IDREFs that refer to IDs: many elements can refer to the same element (multi-ref); and a nested element can refer to an ancestor (cycle). It might also be convenient to use IDs and IDREFs so the XML structure matches another storage format, e.g. database foreign keys.

What do you represent with ID/IDREF?

EDIT Also including <key>/<keyref> from XML Schema.

+1  A: 

I mostly use XML for publishing, not to store data, so I use ID/IDREFs for links and cross-references (where the content of the element with the IDREF will be pulled from the element with the ID).

mirod
+1  A: 

I use XML for serialization, so I use ID/IDREF to break cycles and prevent duplicate serializations. I've also considered using it to "pre-declare" references to external objects which are attached to my graph but not serialized as part of it.

The problem with these approaches is that it's difficult to coax serialization frameworks (i.e. JAX-B) into dynamically determining, at runtime, if an object should be serialized in-place or as a reference.

gibbss