public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine) { XmlElement element = nodeList.Current as XmlElement; ProcessAttributes(element, engine); engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(element.ChildNodes)); }
/// <summary> /// Processes the specified node list. /// </summary> /// <param name = "nodeList">The node list.</param> /// <param name = "engine">The engine.</param> public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine) { var element = (XmlElement)nodeList.Current; ProcessAttributes(element, engine); engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(element.ChildNodes)); }
public XmlNode ProcessInclude(XmlElement element, String includeUri, IXmlProcessorEngine engine) { XmlDocumentFragment frag = null; if (includeUri == null) { throw new ConfigurationProcessingException( String.Format("Found an include node without an 'uri' attribute: {0}", element.BaseURI)); } var uriList = includeUri.Split(','); frag = CreateFragment(element); foreach (var uri in uriList) { using (var resource = engine.GetResource(uri)) { var doc = new XmlDocument(); try { using (var stream = resource.GetStreamReader()) { doc.Load(stream); } } catch (Exception ex) { throw new ConfigurationProcessingException( String.Format("Error processing include node: {0}", includeUri), ex); } engine.PushResource(resource); engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(doc.DocumentElement)); engine.PopResource(); if (element.GetAttribute("preserve-wrapper") == "yes") { AppendChild(frag, doc.DocumentElement); } else { AppendChild(frag, doc.DocumentElement.ChildNodes); } } } return(frag); }
public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine) { XmlElement element = nodeList.Current as XmlElement; bool processContents = ProcessStatement(element, engine); if (processContents) { XmlDocumentFragment fragment = CreateFragment(element); MoveChildNodes(fragment, element); engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(fragment.ChildNodes)); ReplaceItself(fragment, element); } else { RemoveItSelf(element); } }
public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine) { XmlElement element = nodeList.Current as XmlElement; XmlDocumentFragment fragment = CreateFragment(element); foreach (XmlNode child in element.ChildNodes) { if (IgnoreNode(child)) { continue; } XmlElement elem = GetNodeAsElement(element, child); bool found = false; if (elem.Name == WhenElemName) { found = ProcessStatement(elem, engine); } else if (elem.Name == OtherwiseElemName) { found = true; } else { throw new XmlProcessorException("'{0} can not contain only 'when' and 'otherwise' elements found '{1}'", element.Name, elem.Name); } if (found) { if (elem.ChildNodes.Count > 0) { MoveChildNodes(fragment, elem); engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(fragment.ChildNodes)); } break; } } ReplaceItself(fragment, element); }
public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine) { var element = nodeList.Current as XmlElement; var fragment = CreateFragment(element); foreach (XmlNode child in element.ChildNodes) { if (IgnoreNode(child)) { continue; } var elem = GetNodeAsElement(element, child); var found = false; if (elem.Name == WhenElemName) { found = ProcessStatement(elem, engine); } else if (elem.Name == OtherwiseElemName) { found = true; } else { throw new XmlProcessorException("'{0} can not contain only 'when' and 'otherwise' elements found '{1}'", element.Name, elem.Name); } if (found) { if (elem.ChildNodes.Count > 0) { MoveChildNodes(fragment, elem); engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(fragment.ChildNodes)); } break; } } ReplaceItself(fragment, element); }
public XmlNode Process(XmlNode node) { try { if (node.NodeType == XmlNodeType.Document) { node = (node as XmlDocument).DocumentElement; } engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(node)); return(node); } catch (ConfigurationProcessingException) { throw; } catch (Exception ex) { var message = String.Format("Error processing node {0}, inner content {1}", node.Name, node.InnerXml); throw new ConfigurationProcessingException(message, ex); } }
public XmlNode ProcessInclude(XmlElement element, String includeUri, IXmlProcessorEngine engine) { XmlDocumentFragment frag = null; if (includeUri == null) { throw new ConfigurationProcessingException( String.Format("Found an include node without an 'uri' attribute: {0}", element.BaseURI)); } String[] uriList = includeUri.Split(','); frag = CreateFragment(element); foreach(String uri in uriList) { using(IResource resource = engine.GetResource(uri)) { XmlDocument doc = new XmlDocument(); try { using (var stream = resource.GetStreamReader()) { doc.Load(stream); } } catch(Exception ex) { throw new ConfigurationProcessingException( String.Format("Error processing include node: {0}", includeUri), ex); } engine.PushResource(resource); engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(doc.DocumentElement)); engine.PopResource(); if (element.GetAttribute("preserve-wrapper") == "yes") { AppendChild(frag, doc.DocumentElement); } else { AppendChild(frag, doc.DocumentElement.ChildNodes); } } } return frag; }
public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine) { XmlProcessingInstruction node = nodeList.Current as XmlProcessingInstruction; AssertData(node, true); StatementState state = engine.HasFlag(node.Data) ? StatementState.Collect : StatementState.Init; List <XmlNode> nodesToProcess = new List <XmlNode>(); int nestedLevels = 0; RemoveItSelf(nodeList.Current); while (nodeList.MoveNext()) { if (nodeList.Current.NodeType == XmlNodeType.ProcessingInstruction) { XmlProcessingInstruction pi = nodeList.Current as XmlProcessingInstruction; if (pi.Name == EndPiName) { nestedLevels--; if (nestedLevels < 0) { RemoveItSelf(nodeList.Current); break; } } else if (pi.Name == IfPiName) { nestedLevels++; } else if (nestedLevels == 0) { if (pi.Name == ElsePiName || pi.Name == ElsifPiName) { ProcessElseElement(pi, engine, ref state); continue; } } } if (state == StatementState.Collect) { nodesToProcess.Add(nodeList.Current); } else { RemoveItSelf(nodeList.Current); } } if (nestedLevels != -1) { throw new XmlProcessorException("Unbalanced pi if element"); } if (nodesToProcess.Count > 0) { engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(nodesToProcess)); } }
public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine) { XmlProcessingInstruction node = nodeList.Current as XmlProcessingInstruction; AssertData(node, true); StatementState state = engine.HasFlag(node.Data) ? StatementState.Collect : StatementState.Init; List<XmlNode> nodesToProcess = new List<XmlNode>(); int nestedLevels = 0; RemoveItSelf(nodeList.Current); while(nodeList.MoveNext()) { if (nodeList.Current.NodeType == XmlNodeType.ProcessingInstruction) { XmlProcessingInstruction pi = nodeList.Current as XmlProcessingInstruction; if (pi.Name == EndPiName) { nestedLevels--; if (nestedLevels < 0) { RemoveItSelf(nodeList.Current); break; } } else if (pi.Name == IfPiName) { nestedLevels++; } else if (nestedLevels == 0) { if (pi.Name == ElsePiName || pi.Name == ElsifPiName) { ProcessElseElement(pi, engine, ref state); continue; } } } if (state == StatementState.Collect) { nodesToProcess.Add(nodeList.Current); } else { RemoveItSelf(nodeList.Current); } } if (nestedLevels != -1) { throw new XmlProcessorException("Unbalanced pi if element"); } if (nodesToProcess.Count > 0) { engine.DispatchProcessAll(new DefaultXmlProcessorNodeList(nodesToProcess)); } }