/// <summary> /// Set a scalar value in the init section of a component. /// Handles the init sections of APSIM and AusFarm components. /// </summary> /// <param name="compNode">XmlNode for the component found</param> /// <param name="varName">Name of the variable. APSIM - xml tag, AusFarm - init name</param> /// <param name="value">The string value</param> private void SetValue(XmlNode compNode, string varName, string value) { if (compNode != null) { TCompParser comp = new TCompParser(compNode.OuterXml); XmlNode initdata = compNode.SelectSingleNode("initdata"); string newInitDataSection; if (comp.IsAPSRU()) { XmlUtilities.SetValue(initdata, varName, value); } else { //AusFarm inits string cdata = comp.initData(); XmlDocument doc = new XmlDocument(); doc.LoadXml(cdata); XmlNode initSection = doc.DocumentElement; XmlNode val = initSection.SelectSingleNode("/initsection/init[attribute::name=\"" + varName + "\"]/val"); if (val != null) val.InnerText = value; newInitDataSection = initSection.OuterXml; initdata.InnerXml = "<![CDATA[\n" + newInitDataSection + "\n]]>"; } } }