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.Collections.Generic;
2using System.Threading.Tasks;
3using System.Xml;
8
10{
15 {
25 : base(Xml, Name, Start, Length, Expression)
26 {
27 }
28
32 public override string FunctionName => nameof(SelectXmlStr);
33
37 public override string[] DefaultArgumentNames => new string[] { "XML", "XPath" };
38
47 {
48 object Obj = Argument1.AssociatedObjectValue;
49 XmlNodeList Result;
50
51 if (Obj is null)
52 return ObjectValue.Null;
53 else if (Obj is XmlNode N)
54 Result = SelectXml.Evaluate(N, Argument2.AssociatedObjectValue?.ToString() ?? string.Empty);
55 else
56 throw new ScriptRuntimeException("XPath expression only operate on XML.", this);
57
58 int i, c = Result.Count;
59
60 switch (c)
61 {
62 case 0:
63 return ObjectValue.Null;
64
65 case 1:
66 return ToElement(Result[0]);
67
68 default:
69 IElement[] Items = new IElement[c];
70
71 for (i = 0; i < c; i++)
72 Items[i] = ToElement(Result[i]);
73
74 return Operators.Vectors.VectorDefinition.Encapsulate(Items, false, this);
75 }
76 }
77
86 {
87 return Task.FromResult(this.EvaluateScalar(Argument1, Argument2, Variables));
88 }
89
95 public static IElement ToElement(XmlNode Node)
96 {
97 if (Node is XmlText Text)
98 return new StringValue(Text.Value);
99 else if (Node is XmlCDataSection CData)
100 return new StringValue(CData.Value);
101 else if (Node is XmlAttribute Attr)
102 return new StringValue(Attr.Value);
103 else
104 {
105 if (Node.HasChildNodes && Node.FirstChild == Node.LastChild && Node.FirstChild is XmlText Text2)
106 return new StringValue(Text2.Value);
107 else
108 return new ObjectValue(Node);
109 }
110 }
111
112 }
113}
Class managing a script expression.
Definition: Expression.cs:39
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:86
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:15
override string FunctionName
Name of the function
Definition: SelectXmlStr.cs:32
override IElement EvaluateScalar(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: SelectXmlStr.cs:46
override Task< IElement > EvaluateScalarAsync(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: SelectXmlStr.cs:85
SelectXmlStr(ScriptNode Xml, ScriptNode Name, int Start, int Length, Expression Expression)
Performs a literal string XML slection using XPATH.
Definition: SelectXmlStr.cs:24
static IElement ToElement(XmlNode Node)
Encapsulates an XML Node for use in script.
Definition: SelectXmlStr.cs:95
override string[] DefaultArgumentNames
Default Argument names
Definition: SelectXmlStr.cs:37
Basic interface for all types of elements.
Definition: IElement.cs:20
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.