/// <summary> /// Represents an script-based XML document. /// </summary> /// <param name="Root">Root element of document.</param> /// <param name="ProcessingInstructions">Processing Instructions.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public XmlScriptDocument(XmlScriptElement Root, XmlScriptProcessingInstruction[] ProcessingInstructions, int Start, int Length, Expression Expression) : base(Start, Length, Expression) { this.root = Root; this.processingInstructions = ProcessingInstructions; }
/// <summary> /// Calls the callback method for all child nodes. /// </summary> /// <param name="Callback">Callback method to call.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <param name="DepthFirst">If calls are made depth first (true) or on each node and then its leaves (false).</param> /// <returns>If the process was completed.</returns> public override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst) { int i, c = this.processingInstructions.Length; ScriptNode Node; if (DepthFirst) { for (i = 0; i < c; i++) { if (!this.processingInstructions[i].ForAllChildNodes(Callback, State, DepthFirst)) { return(false); } } if (!this.root.ForAllChildNodes(Callback, State, DepthFirst)) { return(false); } } for (i = 0; i < c; i++) { Node = this.processingInstructions[i]; if (!Callback(ref Node, State)) { return(false); } if (Node != this.processingInstructions[i]) { if (Node is XmlScriptProcessingInstruction PI) { this.processingInstructions[i] = PI; } else { throw new ScriptRuntimeException("Incompatible node change.", this); } } } Node = this.root; if (!Callback(ref Node, State)) { return(false); } if (Node != this.root) { if (Node is XmlScriptElement Root) { this.root = Root; } else { throw new ScriptRuntimeException("Incompatible node change.", this); } } if (!DepthFirst) { for (i = 0; i < c; i++) { if (!this.processingInstructions[i].ForAllChildNodes(Callback, State, DepthFirst)) { return(false); } } if (!this.root.ForAllChildNodes(Callback, State, DepthFirst)) { return(false); } } return(true); }