Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SelectXmlStr.cs
1using System.Threading.Tasks;
2using System.Xml;
7
9{
14 {
24 : base(Xml, Name, Start, Length, Expression)
25 {
26 }
27
31 public override string FunctionName => nameof(SelectXmlStr);
32
36 public override string[] DefaultArgumentNames => new string[] { "XML", "XPath" };
37
41 public override bool UpgradeScalarsToSameSet => false;
42
51 {
52 object Obj = Argument1.AssociatedObjectValue;
53 XmlNodeList Result;
54
55 if (Obj is null)
56 return ObjectValue.Null;
57 else if (Obj is XmlNode N)
58 Result = SelectXml.Evaluate(N, ToString(Argument2) ?? string.Empty);
59 else
60 throw new ScriptRuntimeException("XPath expression only operate on XML.", this);
61
62 int i, c = Result.Count;
63
64 switch (c)
65 {
66 case 0:
67 return ObjectValue.Null;
68
69 case 1:
70 return ToElement(Result[0]);
71
72 default:
73 IElement[] Items = new IElement[c];
74
75 for (i = 0; i < c; i++)
76 Items[i] = ToElement(Result[i]);
77
78 return Operators.Vectors.VectorDefinition.Encapsulate(Items, false, this);
79 }
80 }
81
90 {
91 return Task.FromResult(this.EvaluateScalar(Argument1, Argument2, Variables));
92 }
93
99 public static IElement ToElement(XmlNode Node)
100 {
101 if (Node is XmlText Text)
102 return new StringValue(Text.Value);
103 else if (Node is XmlCDataSection CData)
104 return new StringValue(CData.Value);
105 else if (Node is XmlAttribute Attr)
106 return new StringValue(Attr.Value);
107 else
108 {
109 if (Node.HasChildNodes && Node.FirstChild == Node.LastChild && Node.FirstChild is XmlText Text2)
110 return new StringValue(Text2.Value);
111 else
112 return new ObjectValue(Node);
113 }
114 }
115
116 }
117}
Class managing a script expression.
Definition: Expression.cs:41
Base class for funcions of two scalar variables.
ScriptNode Argument2
Function argument 2.
ScriptNode Argument1
Function argument 1.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:88
Collection of variables.
Definition: Variables.cs:25
Performs an XML slection using XPATH.
Definition: SelectXml.cs:15
Performs a literal string XML slection using XPATH.
Definition: SelectXmlStr.cs:14
override string FunctionName
Name of the function
Definition: SelectXmlStr.cs:31
override IElement EvaluateScalar(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: SelectXmlStr.cs:50
override Task< IElement > EvaluateScalarAsync(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: SelectXmlStr.cs:89
SelectXmlStr(ScriptNode Xml, ScriptNode Name, int Start, int Length, Expression Expression)
Performs a literal string XML slection using XPATH.
Definition: SelectXmlStr.cs:23
static IElement ToElement(XmlNode Node)
Encapsulates an XML Node for use in script.
Definition: SelectXmlStr.cs:99
override string[] DefaultArgumentNames
Default Argument names
Definition: SelectXmlStr.cs:36
override bool UpgradeScalarsToSameSet
If scalars should be upgraded to the same set before evaluation.
Definition: SelectXmlStr.cs:41
Basic interface for all types of elements.
Definition: IElement.cs:21
IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.