Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmlNormalizationState.cs
1using System.Collections.Generic;
2using System.Text;
3
4namespace Waher.Content.Xml
5{
10 {
11 private readonly StringBuilder output = new StringBuilder();
12 private readonly Dictionary<string, string> namespceByPrefix = new Dictionary<string, string>();
13 private readonly LinkedList<LinkedList<KeyValuePair<string, string>>> prefixStack = new LinkedList<LinkedList<KeyValuePair<string, string>>>();
14 private LinkedList<KeyValuePair<string, string>> newPrefixes = null;
15
20 {
21 }
22
27 public void Append(string s)
28 {
29 this.output.Append(s);
30 }
31
36 public void Append(char ch)
37 {
38 this.output.Append(ch);
39 }
40
45 public override string ToString()
46 {
47 return this.output.ToString();
48 }
49
56 public bool RegisterPrefix(string Prefix, string Namespace)
57 {
58 if (this.namespceByPrefix.TryGetValue(Prefix, out string PrevNamespace))
59 {
60 if (PrevNamespace == Namespace)
61 return false;
62 }
63 else
64 PrevNamespace = null;
65
66 if (this.newPrefixes is null)
67 this.newPrefixes = new LinkedList<KeyValuePair<string, string>>();
68
69 this.newPrefixes.AddLast(new KeyValuePair<string, string>(Prefix, PrevNamespace));
70 this.namespceByPrefix[Prefix] = Namespace;
71
72 return true;
73 }
74
78 public void PushPrefixes()
79 {
80 this.prefixStack.AddLast(this.newPrefixes);
81 this.newPrefixes = null;
82 }
83
87 public void PopPrefixes()
88 {
89 if (this.prefixStack.Last is null)
90 return;
91
92 LinkedList<KeyValuePair<string, string>> ToRemove = this.prefixStack.Last.Value;
93 this.prefixStack.RemoveLast();
94
95 if (!(ToRemove is null))
96 {
97 foreach (KeyValuePair<string, string> P in ToRemove)
98 {
99 if (P.Value is null)
100 this.namespceByPrefix.Remove(P.Key);
101 else
102 this.namespceByPrefix[P.Key] = P.Value;
103 }
104 }
105 }
106 }
107}
Current state of XML normalization process.
void PushPrefixes()
Pushes current prefix state to the stack.
bool RegisterPrefix(string Prefix, string Namespace)
Registers prefix for element.
XmlNormalizationState()
Current state of XML normalization process.
void Append(char ch)
Appends a character to the output.
void PopPrefixes()
Pops previous prefix state from the stack.
void Append(string s)
Appends a string to the output.