How to retrieve the value from an XML field element
Sometimes one needs to get the value from an element within a K2 XML field. This is usually done within a Server Event. In the below example, I needed to retrieve a URL from a K2 generated XML field. This specific example should work if you do not expect repeating values in the Items node. For scenarios where repeating values are selected, then the XPath would need to be changed.
// get the full XML from the K2 XML field
string strXML = K2.ProcessInstance.XmlFields["SPEventsField"].Value;
// set the XPath to the desired node
string strXPath = "/Items/Item/URL";
// use the helper class to retrieve the value for this element (as set in the XPath) for this XML
string strValue = SourceCode.Workflow.Common.XmlHelper.GetXPathValue(strXML, strXPath);