public void wmFnNodeArrayAdd(string sStepID, string sGroupNode) { dataAccess dc = new dataAccess(); FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates(); try { string sErr = ""; //what's the command type? string sFunctionName = ""; string sSQL = "select function_name from task_step where step_id = '" + sStepID + "'"; if (!dc.sqlGetSingleString(ref sFunctionName, sSQL, ref sErr)) throw new Exception(sErr); if (sFunctionName.Length > 0) { //so, let's get the one we want from the XML template for this step... adjust the indexes, and add it. string sXML = ft.GetCommandXMLTemplate(sFunctionName, ref sErr); if (sErr != "") throw new Exception(sErr); //validate it //parse the doc from the table XDocument xd = XDocument.Parse(sXML); if (xd == null) throw new Exception("Error: Unable to parse Function XML."); //get the original "group" node from the xml_template //here's the rub ... the "sGroupNode" from the actual command instance might have xpath indexes > 1... //but the template DOESN'T! //So, I'm regexing any [#] on the string back to a [1]... that value should be in the template. Regex rx = new Regex(@"\[[0-9]*\]"); string sTemplateNode = rx.Replace(sGroupNode, "[1]"); XElement xGroupNode = xd.XPathSelectElement("//" + sTemplateNode); if (xGroupNode == null) throw new Exception("Error: Unable to add. Source node not found in Template XML. [" + sTemplateNode + "]"); //yeah, this wicked single line aggregates the string value of each node string sNewXML = xGroupNode.Nodes().Aggregate("", (str, node) => str += node.ToString()); if (sNewXML != "") ft.AddNodeToXMLColumn("task_step", "function_xml", "step_id = '" + sStepID + "'", "//" + sGroupNode, sNewXML); } else throw new Exception("Error: Could not loop up XML for command type [" + sFunctionName + "]."); return; } catch (Exception ex) { throw ex; } }