1using System.Collections.Generic;
2using System.Threading.Tasks;
17 private LinkedList<XmlScriptNode> children =
null;
18 private readonly
string name;
19 private readonly
int nrAttributes;
40 this.attributes = Attributes;
43 this.nrAttributes = Attributes.
Length;
48 private void CalcIsAsync()
54 for (
int i = 0; i < this.nrAttributes; i++)
63 LinkedListNode<XmlScriptNode> Loop = this.children?.First;
64 while (!(Loop is
null))
66 if (Loop.Value?.IsAsynchronous ??
false)
88 if (this.children is
null)
89 this.children =
new LinkedList<XmlScriptNode>();
91 this.children.AddLast(Node);
106 LinkedListNode<XmlScriptNode> Loop;
114 for (i = 0; i < this.nrAttributes; i++)
120 Loop = this.children?.First;
121 while (!(Loop is
null))
123 if (!Loop.Value.ForAllChildNodes(Callback, State, Order))
131 bool RecalcIsAsync =
false;
134 if (!(this.xmlns is
null))
136 b = !Callback(this.xmlns, out NewNode, State);
139 this.xmlns = NewAttr;
142 RecalcIsAsync =
true;
145 if (b || (Order ==
SearchMethod.TreeOrder && !
this.xmlns.ForAllChildNodes(Callback, State, Order)))
154 for (i = 0; i < this.nrAttributes; i++)
156 b = !Callback(this.attributes[i], out NewNode, State);
159 this.attributes[i] = Attr;
160 Attr.SetParent(
this);
162 RecalcIsAsync =
true;
165 if (b || (Order ==
SearchMethod.TreeOrder && !
this.attributes[i].ForAllChildNodes(Callback, State, Order)))
174 Loop = this.children?.First;
175 while (!(Loop is
null))
177 b = !Callback(Loop.Value, out NewNode, State);
181 Node2.SetParent(
this);
183 RecalcIsAsync =
true;
186 if (b || (Order ==
SearchMethod.TreeOrder && !Loop.Value.ForAllChildNodes(Callback, State, Order)))
205 for (i = 0; i < this.nrAttributes; i++)
211 Loop = this.children?.First;
212 while (!(Loop is
null))
214 if (!Loop.Value.ForAllChildNodes(Callback, State, Order))
232 string ns = this.xmlns?.GetValue(
Variables) ??
null;
237 if (
Parent is
null ||
string.IsNullOrEmpty(ns =
Parent.NamespaceURI))
243 if (
string.IsNullOrEmpty(ns))
244 E = Document.CreateElement(this.name);
246 E = Document.CreateElement(this.name, ns);
249 E = Document.CreateElement(this.name, ns);
252 Document.AppendChild(E);
256 foreach (XmlScriptAttribute Attr
in this.attributes)
259 if (!(this.children is
null))
261 foreach (XmlScriptNode Node
in this.children)
283 if (this.xmlns is
null)
286 ns = await this.xmlns.GetValueAsync(
Variables);
290 if (
Parent is
null ||
string.IsNullOrEmpty(ns =
Parent.NamespaceURI))
296 if (
string.IsNullOrEmpty(ns))
297 E = Document.CreateElement(this.name);
299 E = Document.CreateElement(this.name, ns);
302 E = Document.CreateElement(this.name, ns);
305 Document.AppendChild(E);
309 foreach (XmlScriptAttribute Attr
in this.attributes)
310 await Attr.BuildAsync(Document, E,
Variables);
312 if (!(this.children is
null))
314 foreach (XmlScriptNode Node
in this.children)
315 await Node.BuildAsync(Document, E,
Variables);
329 if (CheckAgainst is
null)
331 if (!(this.xmlns is
null))
345 if (!(this.children is
null))
357 if (!(CheckAgainst is XmlElement E))
360 if (E.LocalName !=
this.name)
363 if (!(this.xmlns is
null))
365 Result = this.xmlns.
PatternMatch(CheckAgainst.NamespaceURI, AlreadyFound);
372 XmlAttribute Attr2 = E.Attributes[Attr.
Name];
379 XmlNode N = E.FirstChild;
382 if (!(this.children is
null))
394 if (N2.
IsVector && N is XmlElement E2)
396 List<XmlElement> Elements =
new List<XmlElement>() { E2 };
403 else if (N is XmlElement E3)
405 if (E3.LocalName == E2.LocalName &&
406 E3.NamespaceURI == E2.NamespaceURI)
413 else if ((N is XmlText &&
string.IsNullOrWhiteSpace(N.InnerText)) ||
430 else if ((N2 is
XmlScriptText Text &&
string.IsNullOrWhiteSpace(Text.Text)) ||
435 else if ((N is XmlText &&
string.IsNullOrWhiteSpace(N.InnerText)) ||
457 if (N is XmlWhitespace || N is XmlSignificantWhitespace || N is XmlComment ||
458 ((N is XmlText || N is XmlCDataSection) &&
string.IsNullOrWhiteSpace(N.InnerXml)))
477 if (!(CheckAgainst is XmlElement E) || this.name != E.LocalName)
480 if (this.xmlns is
null)
483 return this.xmlns.
IsApplicable(CheckAgainst.NamespaceURI);
Class managing a script expression.
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
ScriptNode Parent
Parent node.
int Start
Start position in script expression.
virtual bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
void SetParent(ScriptNode Parent)
Sets the parent node. Can only be used when expression is being parsed.
Contains information about a variable.
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Abstract base class for XML Script attribute nodes.
override bool IsApplicable(XmlNode CheckAgainst)
If the node is applicable in pattern matching against CheckAgainst .
string Name
Attribute name.
abstract PatternMatchResult PatternMatch(string CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
XmlScriptElement(string Name, XmlScriptAttribute Xmlns, XmlScriptAttribute[] Attributes, int Start, int Length, Expression Expression)
XML Script element node.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
override bool IsApplicable(XmlNode CheckAgainst)
If the node is applicable in pattern matching against CheckAgainst .
override PatternMatchResult PatternMatch(XmlNode CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
void Add(XmlScriptNode Node)
Adds a XML Script node to the element.
override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
Base class for all XML Script nodes in a parsed script tree.
abstract bool IsApplicable(XmlNode CheckAgainst)
If the node is applicable in pattern matching against CheckAgainst .
abstract PatternMatchResult PatternMatch(XmlNode CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
virtual bool IsVector
If the node represents a vector of nodes.
delegate bool ScriptNodeEventHandler(ScriptNode Node, out ScriptNode NewNode, object State)
Delegate for ScriptNode callback methods.
PatternMatchResult
Status result of a pattern matching operation.
SearchMethod
Method to traverse the expression structure