Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XNodeNavigator.cs
Go to the documentation of this file.
3
4namespace System.Xml.XPath;
5
7{
8 internal static readonly string xmlPrefixNamespace = XNamespace.Xml.NamespaceName;
9
10 internal static readonly string xmlnsPrefixNamespace = XNamespace.Xmlns.NamespaceName;
11
12 private static readonly int[] s_ElementContentMasks = new int[10] { 0, 2, 0, 0, 24, 0, 0, 128, 256, 410 };
13
15
17
19
20 private readonly XmlNameTable _nameTable;
21
22 public override string BaseURI
23 {
24 get
25 {
26 if (_source != null)
27 {
28 return _source.BaseUri;
29 }
30 if (_parent != null)
31 {
32 return _parent.BaseUri;
33 }
34 return string.Empty;
35 }
36 }
37
38 public override bool HasAttributes
39 {
40 get
41 {
43 {
44 foreach (XAttribute item in xElement.Attributes())
45 {
46 if (!item.IsNamespaceDeclaration)
47 {
48 return true;
49 }
50 }
51 }
52 return false;
53 }
54 }
55
56 public override bool HasChildren
57 {
58 get
59 {
61 {
62 foreach (XNode item in xContainer.Nodes())
63 {
65 {
66 return true;
67 }
68 }
69 }
70 return false;
71 }
72 }
73
74 public override bool IsEmptyElement
75 {
76 get
77 {
79 {
80 return xElement.IsEmpty;
81 }
82 return false;
83 }
84 }
85
86 public override string LocalName => _nameTable.Add(GetLocalName());
87
88 public override string Name
89 {
90 get
91 {
92 string prefix = GetPrefix();
93 if (prefix.Length == 0)
94 {
95 return _nameTable.Add(GetLocalName());
96 }
97 return _nameTable.Add(prefix + ":" + GetLocalName());
98 }
99 }
100
101 public override string NamespaceURI => _nameTable.Add(GetNamespaceURI());
102
104
105 public override XPathNodeType NodeType
106 {
107 get
108 {
109 if (_source != null)
110 {
111 switch (_source.NodeType)
112 {
113 case XmlNodeType.Element:
114 return XPathNodeType.Element;
115 case XmlNodeType.Attribute:
116 {
118 if (!xAttribute.IsNamespaceDeclaration)
119 {
120 return XPathNodeType.Attribute;
121 }
122 return XPathNodeType.Namespace;
123 }
125 return XPathNodeType.Root;
126 case XmlNodeType.Comment:
127 return XPathNodeType.Comment;
128 case XmlNodeType.ProcessingInstruction:
129 return XPathNodeType.ProcessingInstruction;
130 default:
131 return XPathNodeType.Text;
132 }
133 }
134 return XPathNodeType.Text;
135 }
136 }
137
138 public override string Prefix => _nameTable.Add(GetPrefix());
139
140 public override object UnderlyingObject => _source;
141
142 public override string Value
143 {
144 get
145 {
146 if (_source != null)
147 {
148 switch (_source.NodeType)
149 {
150 case XmlNodeType.Element:
151 return ((XElement)_source).Value;
152 case XmlNodeType.Attribute:
153 return ((XAttribute)_source).Value;
154 case XmlNodeType.Document:
155 {
156 XElement root = ((XDocument)_source).Root;
157 if (root == null)
158 {
159 return string.Empty;
160 }
161 return root.Value;
162 }
163 case XmlNodeType.Text:
164 case XmlNodeType.CDATA:
165 return CollectText((XText)_source);
166 case XmlNodeType.Comment:
167 return ((XComment)_source).Value;
168 case XmlNodeType.ProcessingInstruction:
169 return ((XProcessingInstruction)_source).Data;
170 default:
171 return string.Empty;
172 }
173 }
174 return string.Empty;
175 }
176 }
177
178 int IXmlLineInfo.LineNumber => ((IXmlLineInfo)_source)?.LineNumber ?? 0;
179
180 int IXmlLineInfo.LinePosition => ((IXmlLineInfo)_source)?.LinePosition ?? 0;
181
187
189 {
190 _source = other._source;
191 _parent = other._parent;
192 _nameTable = other._nameTable;
193 }
194
195 private string GetLocalName()
196 {
198 {
199 return xElement.Name.LocalName;
200 }
202 {
203 if (_parent != null && xAttribute.Name.NamespaceName.Length == 0)
204 {
205 return string.Empty;
206 }
207 return xAttribute.Name.LocalName;
208 }
210 {
211 return xProcessingInstruction.Target;
212 }
213 return string.Empty;
214 }
215
216 private string GetNamespaceURI()
217 {
219 {
220 return xElement.Name.NamespaceName;
221 }
223 {
224 if (_parent != null)
225 {
226 return string.Empty;
227 }
228 return xAttribute.Name.NamespaceName;
229 }
230 return string.Empty;
231 }
232
233 private string GetPrefix()
234 {
236 {
237 string prefixOfNamespace = xElement.GetPrefixOfNamespace(xElement.Name.Namespace);
238 if (prefixOfNamespace != null)
239 {
240 return prefixOfNamespace;
241 }
242 return string.Empty;
243 }
245 {
246 if (_parent != null)
247 {
248 return string.Empty;
249 }
250 string prefixOfNamespace2 = xAttribute.GetPrefixOfNamespace(xAttribute.Name.Namespace);
251 if (prefixOfNamespace2 != null)
252 {
253 return prefixOfNamespace2;
254 }
255 }
256 return string.Empty;
257 }
258
259 public override XPathNavigator Clone()
260 {
261 return new XNodeNavigator(this);
262 }
263
265 {
267 {
268 return false;
269 }
270 return IsSamePosition(this, n);
271 }
272
273 public override bool MoveTo(XPathNavigator navigator)
274 {
276 {
277 _source = xNodeNavigator._source;
278 _parent = xNodeNavigator._parent;
279 return true;
280 }
281 return false;
282 }
283
284 public override bool MoveToAttribute(string localName, string namespaceName)
285 {
287 {
288 foreach (XAttribute item in xElement.Attributes())
289 {
290 if (item.Name.LocalName == localName && item.Name.NamespaceName == namespaceName && !item.IsNamespaceDeclaration)
291 {
292 _source = item;
293 return true;
294 }
295 }
296 }
297 return false;
298 }
299
300 public override bool MoveToChild(string localName, string namespaceName)
301 {
303 {
304 foreach (XElement item in xContainer.Elements())
305 {
306 if (item.Name.LocalName == localName && item.Name.NamespaceName == namespaceName)
307 {
308 _source = item;
309 return true;
310 }
311 }
312 }
313 return false;
314 }
315
316 public override bool MoveToChild(XPathNodeType type)
317 {
319 {
320 int num = GetElementContentMask(type);
321 if ((0x18u & (uint)num) != 0 && xContainer.GetParent() == null && xContainer is XDocument)
322 {
323 num &= -25;
324 }
325 foreach (XNode item in xContainer.Nodes())
326 {
327 if (((1 << (int)item.NodeType) & num) != 0)
328 {
329 _source = item;
330 return true;
331 }
332 }
333 }
334 return false;
335 }
336
337 public override bool MoveToFirstAttribute()
338 {
340 {
341 foreach (XAttribute item in xElement.Attributes())
342 {
343 if (!item.IsNamespaceDeclaration)
344 {
345 _source = item;
346 return true;
347 }
348 }
349 }
350 return false;
351 }
352
353 public override bool MoveToFirstChild()
354 {
356 {
357 foreach (XNode item in xContainer.Nodes())
358 {
360 {
361 _source = item;
362 return true;
363 }
364 }
365 }
366 return false;
367 }
368
369 public override bool MoveToFirstNamespace(XPathNamespaceScope scope)
370 {
372 {
373 XAttribute xAttribute = null;
374 switch (scope)
375 {
376 case XPathNamespaceScope.Local:
378 break;
379 case XPathNamespaceScope.ExcludeXml:
381 while (xAttribute != null && xAttribute.Name.LocalName == "xml")
382 {
384 }
385 break;
386 case XPathNamespaceScope.All:
388 if (xAttribute == null)
389 {
391 }
392 break;
393 }
394 if (xAttribute != null)
395 {
398 return true;
399 }
400 }
401 return false;
402 }
403
404 public override bool MoveToId(string id)
405 {
407 }
408
409 public override bool MoveToNamespace(string localName)
410 {
412 {
413 if (localName == "xmlns")
414 {
415 return false;
416 }
417 if (localName != null && localName.Length == 0)
418 {
419 localName = "xmlns";
420 }
422 {
423 if (xAttribute.Name.LocalName == localName)
424 {
427 return true;
428 }
429 }
430 if (localName == "xml")
431 {
434 return true;
435 }
436 }
437 return false;
438 }
439
440 public override bool MoveToNext()
441 {
442 if (_source is XNode xNode)
443 {
444 XContainer parent = xNode.GetParent();
445 if (parent != null)
446 {
447 XNode xNode2 = null;
448 for (XNode xNode3 = xNode; xNode3 != null; xNode3 = xNode2)
449 {
451 if (xNode2 == null)
452 {
453 break;
454 }
455 if (IsContent(parent, xNode2) && (!(xNode3 is XText) || !(xNode2 is XText)))
456 {
457 _source = xNode2;
458 return true;
459 }
460 }
461 }
462 }
463 return false;
464 }
465
466 public override bool MoveToNext(string localName, string namespaceName)
467 {
468 if (_source is XNode xNode)
469 {
470 foreach (XElement item in xNode.ElementsAfterSelf())
471 {
472 if (item.Name.LocalName == localName && item.Name.NamespaceName == namespaceName)
473 {
474 _source = item;
475 return true;
476 }
477 }
478 }
479 return false;
480 }
481
482 public override bool MoveToNext(XPathNodeType type)
483 {
484 if (_source is XNode xNode)
485 {
486 XContainer parent = xNode.GetParent();
487 if (parent != null)
488 {
489 int num = GetElementContentMask(type);
490 if ((0x18u & (uint)num) != 0 && parent.GetParent() == null && parent is XDocument)
491 {
492 num &= -25;
493 }
494 XNode xNode2 = null;
496 while (true)
497 {
499 if (xNode2 == null)
500 {
501 break;
502 }
503 if (((1 << (int)xNode2.NodeType) & num) != 0 && (!(xNode3 is XText) || !(xNode2 is XText)))
504 {
505 _source = xNode2;
506 return true;
507 }
508 xNode3 = xNode2;
509 }
510 }
511 }
512 return false;
513 }
514
515 public override bool MoveToNextAttribute()
516 {
517 if (_source is XAttribute xAttribute && _parent == null)
518 {
519 XElement xElement = (XElement)xAttribute.GetParent();
520 if (xElement != null)
521 {
523 {
524 if (!nextAttribute.IsNamespaceDeclaration)
525 {
527 return true;
528 }
529 }
530 }
531 }
532 return false;
533 }
534
535 public override bool MoveToNextNamespace(XPathNamespaceScope scope)
536 {
538 if (xAttribute != null && _parent != null && !IsXmlNamespaceDeclaration(xAttribute))
539 {
540 switch (scope)
541 {
542 case XPathNamespaceScope.Local:
543 if (xAttribute.GetParent() != _parent)
544 {
545 return false;
546 }
548 break;
549 case XPathNamespaceScope.ExcludeXml:
550 do
551 {
553 }
554 while (xAttribute != null && (xAttribute.Name.LocalName == "xml" || HasNamespaceDeclarationInScope(xAttribute, _parent)));
555 break;
556 case XPathNamespaceScope.All:
557 do
558 {
560 }
563 {
565 }
566 break;
567 }
568 if (xAttribute != null)
569 {
571 return true;
572 }
573 }
574 return false;
575 }
576
577 public override bool MoveToParent()
578 {
579 if (_parent != null)
580 {
582 _parent = null;
583 return true;
584 }
585 XNode parent = _source.GetParent();
586 if (parent != null)
587 {
588 _source = parent;
589 return true;
590 }
591 return false;
592 }
593
594 public override bool MoveToPrevious()
595 {
596 if (_source is XNode xNode)
597 {
598 XContainer parent = xNode.GetParent();
599 if (parent != null)
600 {
601 XNode xNode2 = null;
602 foreach (XNode item in parent.Nodes())
603 {
604 if (item == xNode)
605 {
606 if (xNode2 != null)
607 {
608 _source = xNode2;
609 return true;
610 }
611 return false;
612 }
613 if (IsContent(parent, item))
614 {
615 xNode2 = item;
616 }
617 }
618 }
619 }
620 return false;
621 }
622
623 public override XmlReader ReadSubtree()
624 {
626 {
628 }
629 return xContainer.CreateReader();
630 }
631
633 {
634 return ((IXmlLineInfo)_source)?.HasLineInfo() ?? false;
635 }
636
637 private static string CollectText(XText n)
638 {
639 string text = n.Value;
640 if (n.GetParent() != null)
641 {
642 foreach (XNode item in n.NodesAfterSelf())
643 {
644 if (!(item is XText xText))
645 {
646 break;
647 }
648 text += xText.Value;
649 }
650 }
651 return text;
652 }
653
655 {
657 xmlNameTable.Add(string.Empty);
660 return xmlNameTable;
661 }
662
663 private static bool IsContent(XContainer c, XNode n)
664 {
665 if (c.GetParent() != null || c is XElement)
666 {
667 return true;
668 }
669 return ((1 << (int)n.NodeType) & 0x182) != 0;
670 }
671
673 {
674 if (n1._source == n2._source)
675 {
676 return n1._source.GetParent() == n2._source.GetParent();
677 }
678 return false;
679 }
680
682 {
683 return a == GetXmlNamespaceDeclaration();
684 }
685
687 {
688 return s_ElementContentMasks[(int)type];
689 }
690
692 {
693 XElement xElement = e;
694 do
695 {
698 {
700 }
701 xElement = xElement.Parent;
702 }
703 while (xElement != null);
704 return null;
705 }
706
708 {
709 foreach (XAttribute item in e.Attributes())
710 {
711 if (item.IsNamespaceDeclaration)
712 {
713 return item;
714 }
715 }
716 return null;
717 }
718
720 {
721 XElement xElement = (XElement)a.GetParent();
722 if (xElement == null)
723 {
724 return null;
725 }
728 {
730 }
731 xElement = xElement.Parent;
732 if (xElement == null)
733 {
734 return null;
735 }
737 }
738
740 {
741 XElement parent = a.Parent;
742 if (parent == null)
743 {
744 return null;
745 }
747 for (xAttribute = xAttribute.NextAttribute; xAttribute != null; xAttribute = xAttribute.NextAttribute)
748 {
749 if (xAttribute.IsNamespaceDeclaration)
750 {
751 return xAttribute;
752 }
753 }
754 return null;
755 }
756
765
767 {
768 XName name = a.Name;
769 XElement xElement = e;
770 while (xElement != null && xElement != a.GetParent())
771 {
772 if (xElement.Attribute(name) != null)
773 {
774 return true;
775 }
777 }
778 return false;
779 }
780}
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string NotSupported_MoveToId
Definition SR.cs:74
static string InvalidOperation_BadNodeType
Definition SR.cs:70
Definition SR.cs:7
static int CompareExchange(ref int location1, int value, int comparand)
IEnumerable< XNode > Nodes()
IEnumerable< XElement > Elements()
string NamespaceName
Definition XName.cs:18
static XNamespace Xmlns
Definition XNamespace.cs:28
static XNamespace Xml
Definition XNamespace.cs:26
IEnumerable< XElement > ElementsAfterSelf()
Definition XNode.cs:250
IEnumerable< XNode > NodesAfterSelf()
Definition XNode.cs:220
XmlNodeType NodeType
Definition XObject.cs:51
XDocument? Document
Definition XObject.cs:39
override XmlReader ReadSubtree()
override bool MoveToNamespace(string localName)
static XmlNameTable CreateNameTable()
static string CollectText(XText n)
override bool MoveToNext(XPathNodeType type)
static readonly string xmlnsPrefixNamespace
static bool IsContent(XContainer c, XNode n)
override bool MoveToFirstNamespace(XPathNamespaceScope scope)
override bool MoveToChild(string localName, string namespaceName)
static bool HasNamespaceDeclarationInScope(XAttribute a, XElement e)
override XmlNameTable NameTable
override bool MoveTo(XPathNavigator navigator)
static XAttribute s_XmlNamespaceDeclaration
static readonly int[] s_ElementContentMasks
static readonly string xmlPrefixNamespace
XNodeNavigator(XNode node, XmlNameTable nameTable)
static int GetElementContentMask(XPathNodeType type)
readonly XmlNameTable _nameTable
override XPathNavigator Clone()
static XAttribute GetXmlNamespaceDeclaration()
XNodeNavigator(XNodeNavigator other)
static XAttribute GetNextNamespaceDeclarationGlobal(XAttribute a)
static bool IsXmlNamespaceDeclaration(XAttribute a)
static XAttribute GetFirstNamespaceDeclarationGlobal(XElement e)
override bool MoveToChild(XPathNodeType type)
override bool IsSamePosition(XPathNavigator navigator)
static XAttribute GetFirstNamespaceDeclarationLocal(XElement e)
static XAttribute GetNextNamespaceDeclarationLocal(XAttribute a)
override XPathNodeType NodeType
override bool MoveToId(string id)
static bool IsSamePosition(XNodeNavigator n1, XNodeNavigator n2)
override bool MoveToNextNamespace(XPathNamespaceScope scope)
override bool MoveToNext(string localName, string namespaceName)
override bool MoveToAttribute(string localName, string namespaceName)
string Add(char[] array, int offset, int length)