Working with "custom" XML
The Engine supports the association of arbitrary XML with each event in a DCR graph. This feature is used extensively by the DCR Solutions Portal, Designer, and Active Repository offerings. This document describes how to work with custom XML in event definitions.
Retrieving custom XML
Custom XML lives inside the Marking of an event. Suppose we want to retrive the
custom XML of an event Activity2
in graph graph
:
Path eid = new Path ("Activity2"); // Construct a path for the event
Marking m = graph.GetMarking(eid); // Retrieve the marking of the event
XElement xelem = m.Custom; // Retrieve the custom XML from the marking
It may be convenient to do to these operations in one line, as is done in
the Samples
project:
XElement xelem = graph.GetMarking(new Path("Activity2")).Custom;
Writing custom XML
To write custom XML, replace it in its entirety in the marking. Remember to
write back the updated marking to the graph. Assume we have suitable XML
in a variable custom
of type XElement
.
Path eid = new Path ("Activity2"); // Construct a path for the event
Marking m = graph.GetMarking(eid); // Retrieve the marking of the event
m.Custom = custom; // Set custom XML in marking
graph.SetMarking(eid, m); // Set marking of event
Writing custom XML when constructing events
To set custom XML in events constructed using
[AddEvent](xref:M:DCR.Graph.AddEvent(DCR.Path,DCR.Marking)
and variants, one may first construct the event, then use the pattern of
the preceding section to update the XML. However, custom XML can also be
set directly when constructing a
Marking. Here is how to construct an event at the root
with id A
, label Authorised payout
, and custom XML as specified in the
variable custom
of type XElement
:
XElement custom = ...;
graph.AddEvent(new Path("A"), new Marking("Authorised payout", custom));
See the Marking constructor.