/// <summary> /// Processes the string. /// </summary> /// <param name="node">The node.</param> /// <param name="value">The value.</param> /// <param name="engine">The context.</param> public void ProcessString(XmlNode node, string value, IXmlProcessorEngine engine) { XmlDocumentFragment fragment = CreateFragment(node); Match match; int pos = 0; while ((match = PropertyValidationRegExp.Match(value, pos)).Success) { if (pos < match.Index) { AppendChild(fragment, value.Substring(pos, match.Index - pos)); } string propRef = match.Groups[1].Value; // #!{ propKey } string propKey = match.Groups[2].Value; // propKey XmlNode prop = engine.GetProperty(propKey); if (prop != null) { // When node has a parentNode (not an attribute) // we copy any attributes for the property into the parentNode if (node.ParentNode != null) { MoveAttributes(node.ParentNode as XmlElement, prop as XmlElement); } AppendChild(fragment, prop.ChildNodes); } else if (IsRequiredProperty(propRef)) { throw new XmlProcessorException(String.Format("Required configuration property {0} not found", propKey)); } pos = match.Index + match.Length; } // Appending anything left if (pos > 0 && pos < value.Length) { AppendChild(fragment, value.Substring(pos, value.Length - pos)); } // we only process when there was at least one match // even when the fragment contents is empty since // that could mean that there was a match but the property // reference was a silent property if (pos > 0) { if (node.NodeType == XmlNodeType.Attribute) { node.Value = fragment.InnerText.Trim(); } else { ReplaceNode(node.ParentNode, fragment, node); } } }
/// <summary> /// Processes the string. /// </summary> /// <param name = "node">The node.</param> /// <param name = "value">The value.</param> /// <param name = "engine">The context.</param> public void ProcessString(XmlNode node, string value, IXmlProcessorEngine engine) { var fragment = CreateFragment(node); Match match; var pos = 0; while ((match = PropertyValidationRegExp.Match(value, pos)).Success) { if (pos < match.Index) { AppendChild(fragment, value.Substring(pos, match.Index - pos)); } var propRef = match.Groups[1].Value; // #!{ propKey } var propKey = match.Groups[2].Value; // propKey XmlNode prop = engine.GetProperty(propKey); if (prop != null) { // When node has a parentNode (not an attribute) // we copy any attributes for the property into the parentNode if (node.ParentNode != null) { MoveAttributes(node.ParentNode as XmlElement, prop as XmlElement); } AppendChild(fragment, prop.ChildNodes); } else if (IsRequiredProperty(propRef)) { throw new XmlProcessorException(String.Format("Required configuration property {0} not found", propKey)); } pos = match.Index + match.Length; } // Appending anything left if (pos > 0 && pos < value.Length) { AppendChild(fragment, value.Substring(pos, value.Length - pos)); } // we only process when there was at least one match // even when the fragment contents is empty since // that could mean that there was a match but the property // reference was a silent property if (pos > 0) { if (node.NodeType == XmlNodeType.Attribute) { node.Value = fragment.InnerText.Trim(); } else { ReplaceNode(node.ParentNode, fragment, node); } } }