Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmlScriptProcessingInstruction.cs
1using System.Collections.Generic;
2using System.Text.RegularExpressions;
3using System.Xml;
6
8{
13 {
14 private readonly string text;
15
24 : base(Start, Length, Expression)
25 {
26 this.text = Text;
27 }
28
35 internal override void Build(XmlDocument Document, XmlElement Parent, Variables Variables)
36 {
37 int i = this.text.IndexOf(' ');
38
39 if (i < 0)
40 Document.CreateProcessingInstruction(this.text, string.Empty);
41 else
42 {
43 Match M = xmlDeclaration.Match(this.text);
44
45 if (M.Success && M.Index == 0 && M.Length == this.text.Length)
46 {
47 string Version = M.Groups["Version"].Value;
48 string Encoding = M.Groups["Encoding"].Value;
49 string Standalone = M.Groups["Standalone"].Value;
50
51 Document.AppendChild(Document.CreateXmlDeclaration(Version, Encoding, Standalone));
52 }
53 else
54 {
55 string Target = this.text.Substring(0, i);
56 string Data = this.text.Substring(i + 1).Trim();
57
58 Document.AppendChild(Document.CreateProcessingInstruction(Target, Data));
59 }
60 }
61 }
62
63 private static readonly Regex xmlDeclaration = new Regex("\\s*xml\\s*(((version=['\"](?'Version'[^'\"]*)['\"])|(encoding=['\"](?'Encoding'[^'\"]*)['\"])|(standalone=['\"](?'Standalone'[^'\"]*)['\"]))\\s*)*", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);
64
71 public override PatternMatchResult PatternMatch(XmlNode CheckAgainst, Dictionary<string, IElement> AlreadyFound)
72 {
73 int i = this.text.IndexOf(' ');
74
75 if (i < 0)
76 {
77 return CheckAgainst is XmlProcessingInstruction PI && PI.Target == this.text && string.IsNullOrEmpty(PI.Data) ?
78 PatternMatchResult.Match : PatternMatchResult.NoMatch;
79 }
80 else
81 {
82 Match M = xmlDeclaration.Match(this.text);
83
84 if (M.Success && M.Index == 0 && M.Length == this.text.Length)
85 {
86 string Version = M.Groups["Version"].Value;
87 string Encoding = M.Groups["Encoding"].Value;
88 string Standalone = M.Groups["Standalone"].Value;
89
90 return CheckAgainst is XmlDeclaration D && D.Version == Version && D.Encoding == Encoding &&
91 D.Standalone == Standalone ? PatternMatchResult.Match : PatternMatchResult.NoMatch;
92 }
93 else
94 {
95 string Target = this.text.Substring(0, i);
96 string Data = this.text.Substring(i + 1).Trim();
97
98 return CheckAgainst is XmlProcessingInstruction PI && PI.Target == Target && PI.Data == Data ?
99 PatternMatchResult.Match : PatternMatchResult.NoMatch;
100 }
101 }
102 }
103
109 public override bool IsApplicable(XmlNode CheckAgainst)
110 {
111 return (CheckAgainst is XmlProcessingInstruction || CheckAgainst is XmlDeclaration);
112 }
113
114 }
115}
Class managing a script expression.
Definition: Expression.cs:39
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
ScriptNode Parent
Parent node.
Definition: ScriptNode.cs:126
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Base class for all XML Script leaf nodes in a parsed script tree.
override bool IsApplicable(XmlNode CheckAgainst)
If the node is applicable in pattern matching against CheckAgainst .
XmlScriptProcessingInstruction(string Text, int Start, int Length, Expression Expression)
XML Script processing instruction node.
override PatternMatchResult PatternMatch(XmlNode CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17