Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XmlDocumentNavigator.cs « System.Xml « System.XML « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bdd44a165f651deb7b6dbfe6ed5d0e17eee60dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//
// System.Xml.XmlDocumentNavigator
//
// Author:
//   Jason Diamond <jason@injektilo.org>
//
// (C) 2002 Jason Diamond
//

using System;
using System.Collections;
using System.Xml;
using System.Xml.XPath;

namespace System.Xml
{
	internal class XmlDocumentNavigator : XPathNavigator
	{
		#region Constructors

		[MonoTODO]
		internal XmlDocumentNavigator(XmlNode node)
		{
			this.node = node;
		}

		#endregion

		#region Fields

		private XmlNode node;
		private IEnumerator attributesEnumerator;

		#endregion

		#region Properties

		[MonoTODO]
		public override string BaseURI {
			get {
				throw new NotImplementedException ();
			}
		}

		public override bool HasAttributes {
			get {
				if (node.Attributes != null)
					foreach (XmlAttribute attribute in node.Attributes)
						if (attribute.NamespaceURI != "http://www.w3.org/2000/xmlns/")
							return true;
				return false;
			}
		}

		public override bool HasChildren {
			get {
				XPathNodeType nodeType = NodeType;
				bool canHaveChildren = nodeType == XPathNodeType.Root || nodeType == XPathNodeType.Element;
				return canHaveChildren && node.FirstChild != null;
			}
		}

		public override bool IsEmptyElement {
			get {
				return node.NodeType == XmlNodeType.Element && !HasChildren;
			}
		}

		public override string LocalName {
			get {
				XPathNodeType nodeType = NodeType;
				bool canHaveName = 
					nodeType == XPathNodeType.Element || 
					nodeType == XPathNodeType.Attribute || 
					nodeType == XPathNodeType.ProcessingInstruction ||
					nodeType == XPathNodeType.Namespace;
				return canHaveName ? node.LocalName : String.Empty;
			}
		}

		public override string Name {
			get {
				XPathNodeType nodeType = NodeType;
				bool canHaveName = 
					nodeType == XPathNodeType.Element || 
					nodeType == XPathNodeType.Attribute || 
					nodeType == XPathNodeType.ProcessingInstruction ||
					nodeType == XPathNodeType.Namespace;
				return canHaveName ? node.Name : String.Empty;
			}
		}

		public override string NamespaceURI {
			get {
				return node.NamespaceURI;
			}
		}

		[MonoTODO]
		public override XmlNameTable NameTable {
			get {
				throw new NotImplementedException ();
			}
		}

		public override XPathNodeType NodeType {
			get {
				switch (node.NodeType) {
				case XmlNodeType.Document:
					return XPathNodeType.Root;
				case XmlNodeType.Element:
					return XPathNodeType.Element;
				case XmlNodeType.Attribute:
					return XPathNodeType.Attribute;
				case XmlNodeType.Text:
					return XPathNodeType.Text;
				case XmlNodeType.Whitespace:
					return XPathNodeType.Whitespace;
				case XmlNodeType.SignificantWhitespace:
					return XPathNodeType.SignificantWhitespace;
				case XmlNodeType.Comment:
					return XPathNodeType.Comment;
				case XmlNodeType.ProcessingInstruction:
					return XPathNodeType.ProcessingInstruction;
				}
				throw new InvalidOperationException ();
			}
		}

		public override string Prefix {
			get {
				return node.Prefix;
			}
		}

		public override string Value {
			get {
				switch (NodeType) {
				case XPathNodeType.Attribute:
					return node.Value;
				case XPathNodeType.Element:
					return node.InnerText;
				case XPathNodeType.Comment:
					return node.Value;
				case XPathNodeType.ProcessingInstruction:
					return node.Value;
				case XPathNodeType.Text:
					return node.Value;
				case XPathNodeType.Whitespace:
					return node.Value;
				case XPathNodeType.SignificantWhitespace:
					return node.Value;
				case XPathNodeType.Root:
					return node.InnerText;
				}
				return String.Empty;
			}
		}

		[MonoTODO]
		public override string XmlLang {
			get {
				throw new NotImplementedException ();
			}
		}

		#endregion

		#region Methods

		public override XPathNavigator Clone ()
		{
			return new XmlDocumentNavigator (node);
		}

		[MonoTODO]
		public override string GetAttribute (string localName, string namespaceURI)
		{
			throw new NotImplementedException ();
		}

		[MonoTODO]
		public override string GetNamespace (string name)
		{
			throw new NotImplementedException ();
		}
		
		public override bool IsSamePosition (XPathNavigator other)
		{
			XmlDocumentNavigator otherDocumentNavigator = other as XmlDocumentNavigator;
			if (otherDocumentNavigator != null)
				return node == otherDocumentNavigator.node;
			return false;
		}

		public override bool MoveTo (XPathNavigator other)
		{
			XmlDocumentNavigator otherDocumentNavigator = other as XmlDocumentNavigator;
			if (otherDocumentNavigator != null) {
				if (node.OwnerDocument == otherDocumentNavigator.node.OwnerDocument) {
					node = otherDocumentNavigator.node;
					return true;
				}
			}
			return false;
		}

		[MonoTODO]
		public override bool MoveToAttribute (string localName, string namespaceURI)
		{
			throw new NotImplementedException ();
		}

		public override bool MoveToFirst ()
		{
			if (node.NodeType != XmlNodeType.Attribute && node.ParentNode != null) {
				node = node.ParentNode.FirstChild;
				return true;
			}
			return false;
		}

		public override bool MoveToFirstAttribute ()
		{
			if (NodeType == XPathNodeType.Element) {
				attributesEnumerator = node.Attributes.GetEnumerator ();
				return MoveToNextAttribute ();
			}
			return false;
		}

		public override bool MoveToFirstChild ()
		{
			if (HasChildren) {
				node = node.FirstChild;
				return true;
			}
			return false;
		}

		[MonoTODO]
		public override bool MoveToFirstNamespace (XPathNamespaceScope namespaceScope)
		{
			throw new NotImplementedException ();
		}

		[MonoTODO]
		public override bool MoveToId (string id)
		{
			throw new NotImplementedException ();
		}

		[MonoTODO]
		public override bool MoveToNamespace (string name)
		{
			throw new NotImplementedException ();
		}

		public override bool MoveToNext ()
		{
			if (node.NextSibling != null) {
				node = node.NextSibling;
				return true;
			}
			return false;
		}

		public override bool MoveToNextAttribute ()
		{
			if (attributesEnumerator != null && attributesEnumerator.MoveNext ()) {
				node = attributesEnumerator.Current as XmlAttribute;
				return true;
			}
			return false;
		}

		[MonoTODO]
		public override bool MoveToNextNamespace (XPathNamespaceScope namespaceScope)
		{
			throw new NotImplementedException ();
		}

		public override bool MoveToParent ()
		{
			if (node.ParentNode != null) {
				node = node.ParentNode;
				return true;
			}
			return false;
		}

		public override bool MoveToPrevious ()
		{
			if (node.PreviousSibling != null) {
				node = node.PreviousSibling;
				return true;
			}
			return false;
		}

		public override void MoveToRoot ()
		{
			if (node.NodeType != XmlNodeType.Document)
				node = node.OwnerDocument;
		}

		internal XmlNode Node { get { return node; } }

		#endregion
	}
}