Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmlNormalizationState.cs
2using System.Text;
4
5namespace Waher.Content.Xml
6{
11 {
12 private readonly StringBuilder output = new StringBuilder();
13 private readonly Dictionary<string, string> namespceByPrefix = new Dictionary<string, string>();
15 private ChunkedList<KeyValuePair<string, string>> newPrefixes = null;
16
21 {
22 }
23
28 public void Append(string s)
29 {
30 this.output.Append(s);
31 }
32
37 public void Append(char ch)
38 {
39 this.output.Append(ch);
40 }
41
46 public override string ToString()
47 {
48 return this.output.ToString();
49 }
50
57 public bool RegisterPrefix(string Prefix, string Namespace)
58 {
59 if (this.namespceByPrefix.TryGetValue(Prefix, out string PrevNamespace))
60 {
61 if (PrevNamespace == Namespace)
62 return false;
63 }
64 else
65 PrevNamespace = null;
66
67 if (this.newPrefixes is null)
68 this.newPrefixes = new ChunkedList<KeyValuePair<string, string>>();
69
70 this.newPrefixes.Add(new KeyValuePair<string, string>(Prefix, PrevNamespace));
71 this.namespceByPrefix[Prefix] = Namespace;
72
73 return true;
74 }
75
79 public void PushPrefixes()
80 {
81 this.prefixStack.Add(this.newPrefixes);
82 this.newPrefixes = null;
83 }
84
88 public void PopPrefixes()
89 {
90 if (!this.prefixStack.HasLastItem)
91 return;
92
93 ChunkedList<KeyValuePair<string, string>> ToRemove = 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.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
T RemoveLast()
Removes the last item in the collection.
Definition: ChunkedList.cs:911
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272