Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DocumentXPathNavigator.cs
Go to the documentation of this file.
3using System.Text;
6
7namespace System.Xml;
8
10{
11 private readonly XmlDocument _document;
12
14
15 private int _attributeIndex;
16
18
20
21 public override XPathNodeType NodeType
22 {
23 get
24 {
26 return _source.XPNodeType;
27 }
28 }
29
30 public override string LocalName => _source.XPLocalName;
31
32 public override string NamespaceURI
33 {
34 get
35 {
36 if (_source is XmlAttribute { IsNamespace: not false })
37 {
38 return string.Empty;
39 }
40 return _source.NamespaceURI;
41 }
42 }
43
44 public override string Name
45 {
46 get
47 {
48 switch (_source.NodeType)
49 {
50 case XmlNodeType.Element:
51 case XmlNodeType.ProcessingInstruction:
52 return _source.Name;
53 case XmlNodeType.Attribute:
54 if (((XmlAttribute)_source).IsNamespace)
55 {
56 string localName = _source.LocalName;
57 if (Ref.Equal(localName, _document.strXmlns))
58 {
59 return string.Empty;
60 }
61 return localName;
62 }
63 return _source.Name;
64 default:
65 return string.Empty;
66 }
67 }
68 }
69
70 public override string Prefix
71 {
72 get
73 {
74 if (_source is XmlAttribute { IsNamespace: not false })
75 {
76 return string.Empty;
77 }
78 return _source.Prefix;
79 }
80 }
81
82 public override string Value
83 {
84 get
85 {
86 switch (_source.NodeType)
87 {
88 case XmlNodeType.Element:
89 case XmlNodeType.DocumentFragment:
90 return _source.InnerText;
91 case XmlNodeType.Document:
92 return ValueDocument;
93 case XmlNodeType.Text:
94 case XmlNodeType.CDATA:
95 case XmlNodeType.Whitespace:
96 case XmlNodeType.SignificantWhitespace:
97 return ValueText;
98 default:
99 return _source.Value;
100 }
101 }
102 }
103
104 private string ValueDocument
105 {
106 get
107 {
109 if (documentElement != null)
110 {
111 return documentElement.InnerText;
112 }
113 return string.Empty;
114 }
115 }
116
117 private string ValueText
118 {
119 get
120 {
122 string text = _source.Value;
124 if (xmlNode != null && xmlNode.IsText)
125 {
127 do
128 {
129 stringBuilder.Append(xmlNode.Value);
131 }
132 while (xmlNode != null && xmlNode.IsText);
133 text = stringBuilder.ToString();
134 }
135 return text;
136 }
137 }
138
139 public override string BaseURI => _source.BaseURI;
140
141 public override bool IsEmptyElement
142 {
143 get
144 {
146 {
147 return xmlElement.IsEmpty;
148 }
149 return false;
150 }
151 }
152
153 public override string XmlLang => _source.XmlLang;
154
155 public override object UnderlyingObject
156 {
157 get
158 {
160 return _source;
161 }
162 }
163
164 public override bool HasAttributes
165 {
166 get
167 {
169 {
170 XmlAttributeCollection attributes = xmlElement.Attributes;
171 for (int i = 0; i < attributes.Count; i++)
172 {
173 XmlAttribute xmlAttribute = attributes[i];
174 if (!xmlAttribute.IsNamespace)
175 {
176 return true;
177 }
178 }
179 }
180 return false;
181 }
182 }
183
184 public override bool HasChildren
185 {
186 get
187 {
188 switch (_source.NodeType)
189 {
190 case XmlNodeType.Element:
191 {
193 if (xmlNode == null)
194 {
195 return false;
196 }
197 return true;
198 }
199 case XmlNodeType.Document:
200 case XmlNodeType.DocumentFragment:
201 {
203 if (xmlNode == null)
204 {
205 return false;
206 }
207 while (!IsValidChild(_source, xmlNode))
208 {
210 if (xmlNode == null)
211 {
212 return false;
213 }
214 }
215 return true;
216 }
217 default:
218 return false;
219 }
220 }
221 }
222
224
225 public override bool CanEdit => true;
226
232
234 {
235 _document = other._document;
236 _source = other._source;
237 _attributeIndex = other._attributeIndex;
238 _namespaceParent = other._namespaceParent;
239 }
240
241 public override XPathNavigator Clone()
242 {
243 return new DocumentXPathNavigator(this);
244 }
245
246 public override void SetValue(string value)
247 {
248 if (value == null)
249 {
250 throw new ArgumentNullException("value");
251 }
253 switch (source.NodeType)
254 {
255 case XmlNodeType.Attribute:
256 if (!((XmlAttribute)source).IsNamespace)
257 {
259 return;
260 }
261 break;
262 case XmlNodeType.Text:
263 case XmlNodeType.CDATA:
264 case XmlNodeType.Whitespace:
265 case XmlNodeType.SignificantWhitespace:
266 {
268 source = _source;
270 if (source != xmlNode)
271 {
272 if (source.IsReadOnly)
273 {
275 }
277 }
278 goto case XmlNodeType.Element;
279 }
280 case XmlNodeType.Element:
281 case XmlNodeType.ProcessingInstruction:
282 case XmlNodeType.Comment:
284 return;
285 }
287 }
288
289 public override string GetAttribute(string localName, string namespaceURI)
290 {
291 return _source.GetXPAttribute(localName, namespaceURI);
292 }
293
294 public override bool MoveToAttribute(string localName, string namespaceURI)
295 {
297 {
298 XmlAttributeCollection attributes = xmlElement.Attributes;
299 for (int i = 0; i < attributes.Count; i++)
300 {
301 XmlAttribute xmlAttribute = attributes[i];
302 if (xmlAttribute.LocalName == localName && xmlAttribute.NamespaceURI == namespaceURI)
303 {
304 if (!xmlAttribute.IsNamespace)
305 {
307 _attributeIndex = i;
308 return true;
309 }
310 return false;
311 }
312 }
313 }
314 return false;
315 }
316
317 public override bool MoveToFirstAttribute()
318 {
320 {
321 XmlAttributeCollection attributes = xmlElement.Attributes;
322 for (int i = 0; i < attributes.Count; i++)
323 {
324 XmlAttribute xmlAttribute = attributes[i];
325 if (!xmlAttribute.IsNamespace)
326 {
328 _attributeIndex = i;
329 return true;
330 }
331 }
332 }
333 return false;
334 }
335
336 public override bool MoveToNextAttribute()
337 {
338 if (!(_source is XmlAttribute { IsNamespace: false } xmlAttribute))
339 {
340 return false;
341 }
343 {
344 return false;
345 }
346 for (int i = _attributeIndex + 1; i < attributes.Count; i++)
347 {
348 XmlAttribute xmlAttribute2 = attributes[i];
349 if (!xmlAttribute2.IsNamespace)
350 {
352 _attributeIndex = i;
353 return true;
354 }
355 }
356 return false;
357 }
358
359 public override string GetNamespace(string name)
360 {
362 while (xmlNode != null && xmlNode.NodeType != XmlNodeType.Element)
363 {
365 }
367 if (xmlElement != null)
368 {
369 string localName = ((name == null || name.Length == 0) ? _document.strXmlns : name);
370 string strReservedXmlns = _document.strReservedXmlns;
371 do
372 {
373 XmlAttribute attributeNode = xmlElement.GetAttributeNode(localName, strReservedXmlns);
374 if (attributeNode != null)
375 {
376 return attributeNode.Value;
377 }
379 }
380 while (xmlElement != null);
381 }
382 if (name == _document.strXml)
383 {
385 }
386 if (name == _document.strXmlns)
387 {
389 }
390 return string.Empty;
391 }
392
393 public override bool MoveToNamespace(string name)
394 {
395 if (name == _document.strXmlns)
396 {
397 return false;
398 }
400 if (xmlElement != null)
401 {
402 string localName = ((name == null || name.Length == 0) ? _document.strXmlns : name);
403 string strReservedXmlns = _document.strReservedXmlns;
404 do
405 {
406 XmlAttribute attributeNode = xmlElement.GetAttributeNode(localName, strReservedXmlns);
407 if (attributeNode != null)
408 {
411 return true;
412 }
414 }
415 while (xmlElement != null);
416 if (name == _document.strXml)
417 {
420 return true;
421 }
422 }
423 return false;
424 }
425
426 public override bool MoveToFirstNamespace(XPathNamespaceScope scope)
427 {
429 {
430 return false;
431 }
432 int index = int.MaxValue;
433 switch (scope)
434 {
435 case XPathNamespaceScope.Local:
436 {
437 if (!xmlElement.HasAttributes)
438 {
439 return false;
440 }
441 XmlAttributeCollection attributes = xmlElement.Attributes;
442 if (!MoveToFirstNamespaceLocal(attributes, ref index))
443 {
444 return false;
445 }
446 _source = attributes[index];
449 break;
450 }
451 case XPathNamespaceScope.ExcludeXml:
452 {
453 XmlAttributeCollection attributes = xmlElement.Attributes;
454 if (!MoveToFirstNamespaceGlobal(ref attributes, ref index))
455 {
456 return false;
457 }
458 XmlAttribute xmlAttribute = attributes[index];
459 while (Ref.Equal(xmlAttribute.LocalName, _document.strXml))
460 {
461 if (!MoveToNextNamespaceGlobal(ref attributes, ref index))
462 {
463 return false;
464 }
465 xmlAttribute = attributes[index];
466 }
470 break;
471 }
472 case XPathNamespaceScope.All:
473 {
474 XmlAttributeCollection attributes = xmlElement.Attributes;
475 if (!MoveToFirstNamespaceGlobal(ref attributes, ref index))
476 {
478 }
479 else
480 {
481 _source = attributes[index];
483 }
485 break;
486 }
487 default:
488 return false;
489 }
490 return true;
491 }
492
493 private static bool MoveToFirstNamespaceLocal(XmlAttributeCollection attributes, ref int index)
494 {
495 for (int num = attributes.Count - 1; num >= 0; num--)
496 {
497 XmlAttribute xmlAttribute = attributes[num];
498 if (xmlAttribute.IsNamespace)
499 {
500 index = num;
501 return true;
502 }
503 }
504 return false;
505 }
506
507 private static bool MoveToFirstNamespaceGlobal(ref XmlAttributeCollection attributes, ref int index)
508 {
509 if (MoveToFirstNamespaceLocal(attributes, ref index))
510 {
511 return true;
512 }
513 for (XmlElement xmlElement = attributes.parent.ParentNode as XmlElement; xmlElement != null; xmlElement = xmlElement.ParentNode as XmlElement)
514 {
515 if (xmlElement.HasAttributes)
516 {
517 attributes = xmlElement.Attributes;
518 if (MoveToFirstNamespaceLocal(attributes, ref index))
519 {
520 return true;
521 }
522 }
523 }
524 return false;
525 }
526
527 public override bool MoveToNextNamespace(XPathNamespaceScope scope)
528 {
529 if (!(_source is XmlAttribute { IsNamespace: not false } xmlAttribute))
530 {
531 return false;
532 }
535 {
536 return false;
537 }
538 switch (scope)
539 {
540 case XPathNamespaceScope.Local:
541 if (xmlAttribute.OwnerElement != _namespaceParent)
542 {
543 return false;
544 }
545 if (!MoveToNextNamespaceLocal(attributes, ref index))
546 {
547 return false;
548 }
549 _source = attributes[index];
551 break;
552 case XPathNamespaceScope.ExcludeXml:
553 {
555 string localName;
556 do
557 {
558 if (!MoveToNextNamespaceGlobal(ref attributes, ref index))
559 {
560 return false;
561 }
562 xmlAttribute2 = attributes[index];
563 localName = xmlAttribute2.LocalName;
564 }
565 while (PathHasDuplicateNamespace(xmlAttribute2.OwnerElement, _namespaceParent, localName) || Ref.Equal(localName, _document.strXml));
568 break;
569 }
570 case XPathNamespaceScope.All:
571 {
573 do
574 {
575 if (!MoveToNextNamespaceGlobal(ref attributes, ref index))
576 {
578 {
579 return false;
580 }
582 return true;
583 }
584 xmlAttribute2 = attributes[index];
585 }
589 break;
590 }
591 default:
592 return false;
593 }
594 return true;
595 }
596
597 private static bool MoveToNextNamespaceLocal(XmlAttributeCollection attributes, ref int index)
598 {
599 for (int num = index - 1; num >= 0; num--)
600 {
601 XmlAttribute xmlAttribute = attributes[num];
602 if (xmlAttribute.IsNamespace)
603 {
604 index = num;
605 return true;
606 }
607 }
608 return false;
609 }
610
611 private static bool MoveToNextNamespaceGlobal(ref XmlAttributeCollection attributes, ref int index)
612 {
613 if (MoveToNextNamespaceLocal(attributes, ref index))
614 {
615 return true;
616 }
617 for (XmlElement xmlElement = attributes.parent.ParentNode as XmlElement; xmlElement != null; xmlElement = xmlElement.ParentNode as XmlElement)
618 {
619 if (xmlElement.HasAttributes)
620 {
621 attributes = xmlElement.Attributes;
622 if (MoveToFirstNamespaceLocal(attributes, ref index))
623 {
624 return true;
625 }
626 }
627 }
628 return false;
629 }
630
631 private bool PathHasDuplicateNamespace(XmlElement top, XmlElement bottom, string localName)
632 {
633 XmlElement xmlElement = bottom;
634 string strReservedXmlns = _document.strReservedXmlns;
635 while (xmlElement != null && xmlElement != top)
636 {
637 XmlAttribute attributeNode = xmlElement.GetAttributeNode(localName, strReservedXmlns);
638 if (attributeNode != null)
639 {
640 return true;
641 }
643 }
644 return false;
645 }
646
647 public override string LookupNamespace(string prefix)
648 {
649 string text = base.LookupNamespace(prefix);
650 if (text != null)
651 {
653 }
654 return text;
655 }
656
657 public override bool MoveToNext()
658 {
660 if (xmlNode == null)
661 {
662 return false;
663 }
664 if (xmlNode.IsText && _source.IsText)
665 {
667 if (xmlNode == null)
668 {
669 return false;
670 }
671 }
672 XmlNode parent = ParentNode(xmlNode);
673 while (!IsValidChild(parent, xmlNode))
674 {
676 if (xmlNode == null)
677 {
678 return false;
679 }
680 }
682 return true;
683 }
684
685 public override bool MoveToPrevious()
686 {
688 if (xmlNode == null)
689 {
690 return false;
691 }
692 if (xmlNode.IsText)
693 {
694 if (_source.IsText)
695 {
697 if (xmlNode == null)
698 {
699 return false;
700 }
701 }
702 else
703 {
705 }
706 }
707 XmlNode parent = ParentNode(xmlNode);
708 while (!IsValidChild(parent, xmlNode))
709 {
711 if (xmlNode == null)
712 {
713 return false;
714 }
715 }
717 return true;
718 }
719
720 public override bool MoveToFirst()
721 {
722 if (_source.NodeType == XmlNodeType.Attribute)
723 {
724 return false;
725 }
727 if (xmlNode == null)
728 {
729 return false;
730 }
732 while (!IsValidChild(xmlNode, xmlNode2))
733 {
735 if (xmlNode2 == null)
736 {
737 return false;
738 }
739 }
741 return true;
742 }
743
744 public override bool MoveToFirstChild()
745 {
747 switch (_source.NodeType)
748 {
749 case XmlNodeType.Element:
751 if (xmlNode == null)
752 {
753 return false;
754 }
755 break;
756 case XmlNodeType.Document:
757 case XmlNodeType.DocumentFragment:
759 if (xmlNode == null)
760 {
761 return false;
762 }
763 while (!IsValidChild(_source, xmlNode))
764 {
766 if (xmlNode == null)
767 {
768 return false;
769 }
770 }
771 break;
772 default:
773 return false;
774 }
776 return true;
777 }
778
779 public override bool MoveToParent()
780 {
782 if (xmlNode != null)
783 {
785 return true;
786 }
788 {
790 if (xmlNode != null)
791 {
793 _namespaceParent = null;
794 return true;
795 }
796 }
797 return false;
798 }
799
800 public override void MoveToRoot()
801 {
802 while (true)
803 {
805 if (xmlNode == null)
806 {
808 {
809 break;
810 }
812 if (xmlNode == null)
813 {
814 break;
815 }
816 }
818 }
819 _namespaceParent = null;
820 }
821
822 public override bool MoveTo(XPathNavigator other)
823 {
825 {
827 _attributeIndex = documentXPathNavigator._attributeIndex;
828 _namespaceParent = documentXPathNavigator._namespaceParent;
829 return true;
830 }
831 return false;
832 }
833
834 public override bool MoveToId(string id)
835 {
837 if (elementById != null)
838 {
840 _namespaceParent = null;
841 return true;
842 }
843 return false;
844 }
845
846 public override bool MoveToChild(string localName, string namespaceUri)
847 {
848 if (_source.NodeType == XmlNodeType.Attribute)
849 {
850 return false;
851 }
853 if (xmlNode != null)
854 {
855 do
856 {
857 if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.LocalName == localName && xmlNode.NamespaceURI == namespaceUri)
858 {
860 return true;
861 }
863 }
864 while (xmlNode != null);
865 }
866 return false;
867 }
868
869 public override bool MoveToChild(XPathNodeType type)
870 {
871 if (_source.NodeType == XmlNodeType.Attribute)
872 {
873 return false;
874 }
876 if (xmlNode != null)
877 {
879 if (contentKindMask == 0)
880 {
881 return false;
882 }
883 do
884 {
885 if (((1 << (int)xmlNode.XPNodeType) & contentKindMask) != 0)
886 {
888 return true;
889 }
891 }
892 while (xmlNode != null);
893 }
894 return false;
895 }
896
897 public override bool MoveToFollowing(string localName, string namespaceUri, XPathNavigator end)
898 {
899 XmlNode xmlNode = null;
901 if (documentXPathNavigator != null)
902 {
903 if (_document != documentXPathNavigator._document)
904 {
905 return false;
906 }
907 XmlNodeType nodeType = documentXPathNavigator._source.NodeType;
908 if (nodeType == XmlNodeType.Attribute)
909 {
911 if (!documentXPathNavigator.MoveToNonDescendant())
912 {
913 return false;
914 }
915 }
917 }
919 if (xmlNode2.NodeType == XmlNodeType.Attribute)
920 {
921 xmlNode2 = ((XmlAttribute)xmlNode2).OwnerElement;
922 if (xmlNode2 == null)
923 {
924 return false;
925 }
926 }
927 do
928 {
929 XmlNode firstChild = xmlNode2.FirstChild;
930 if (firstChild != null)
931 {
933 }
934 else
935 {
937 while (true)
938 {
939 nextSibling = xmlNode2.NextSibling;
940 if (nextSibling != null)
941 {
942 break;
943 }
944 XmlNode parentNode = xmlNode2.ParentNode;
945 if (parentNode != null)
946 {
947 xmlNode2 = parentNode;
948 continue;
949 }
950 return false;
951 }
953 }
954 if (xmlNode2 == xmlNode)
955 {
956 return false;
957 }
958 }
959 while (xmlNode2.NodeType != XmlNodeType.Element || xmlNode2.LocalName != localName || xmlNode2.NamespaceURI != namespaceUri);
961 return true;
962 }
963
965 {
966 XmlNode xmlNode = null;
968 if (documentXPathNavigator != null)
969 {
970 if (_document != documentXPathNavigator._document)
971 {
972 return false;
973 }
974 XmlNodeType nodeType = documentXPathNavigator._source.NodeType;
975 if (nodeType == XmlNodeType.Attribute)
976 {
978 if (!documentXPathNavigator.MoveToNonDescendant())
979 {
980 return false;
981 }
982 }
984 }
986 if (contentKindMask == 0)
987 {
988 return false;
989 }
991 switch (xmlNode2.NodeType)
992 {
993 case XmlNodeType.Attribute:
994 xmlNode2 = ((XmlAttribute)xmlNode2).OwnerElement;
995 if (xmlNode2 == null)
996 {
997 return false;
998 }
999 break;
1000 case XmlNodeType.Text:
1001 case XmlNodeType.CDATA:
1002 case XmlNodeType.Whitespace:
1003 case XmlNodeType.SignificantWhitespace:
1005 break;
1006 }
1007 do
1008 {
1009 XmlNode firstChild = xmlNode2.FirstChild;
1010 if (firstChild != null)
1011 {
1013 }
1014 else
1015 {
1017 while (true)
1018 {
1019 nextSibling = xmlNode2.NextSibling;
1020 if (nextSibling != null)
1021 {
1022 break;
1023 }
1024 XmlNode parentNode = xmlNode2.ParentNode;
1025 if (parentNode != null)
1026 {
1027 xmlNode2 = parentNode;
1028 continue;
1029 }
1030 return false;
1031 }
1033 }
1034 if (xmlNode2 == xmlNode)
1035 {
1036 return false;
1037 }
1038 }
1039 while (((1 << (int)xmlNode2.XPNodeType) & contentKindMask) == 0);
1040 _source = xmlNode2;
1041 return true;
1042 }
1043
1044 public override bool MoveToNext(string localName, string namespaceUri)
1045 {
1047 if (xmlNode == null)
1048 {
1049 return false;
1050 }
1051 do
1052 {
1053 if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.LocalName == localName && xmlNode.NamespaceURI == namespaceUri)
1054 {
1055 _source = xmlNode;
1056 return true;
1057 }
1059 }
1060 while (xmlNode != null);
1061 return false;
1062 }
1063
1064 public override bool MoveToNext(XPathNodeType type)
1065 {
1067 if (xmlNode == null)
1068 {
1069 return false;
1070 }
1071 if (xmlNode.IsText && _source.IsText)
1072 {
1074 if (xmlNode == null)
1075 {
1076 return false;
1077 }
1078 }
1080 if (contentKindMask == 0)
1081 {
1082 return false;
1083 }
1084 do
1085 {
1086 if (((1 << (int)xmlNode.XPNodeType) & contentKindMask) != 0)
1087 {
1088 _source = xmlNode;
1089 return true;
1090 }
1092 }
1093 while (xmlNode != null);
1094 return false;
1095 }
1096
1098 {
1100 {
1101 CalibrateText();
1102 documentXPathNavigator.CalibrateText();
1103 if (_source == documentXPathNavigator._source)
1104 {
1105 return _namespaceParent == documentXPathNavigator._namespaceParent;
1106 }
1107 return false;
1108 }
1109 return false;
1110 }
1111
1112 public override bool IsDescendant([NotNullWhen(true)] XPathNavigator other)
1113 {
1115 {
1117 }
1118 return false;
1119 }
1120
1121 public override bool CheckValidity(XmlSchemaSet schemas, ValidationEventHandler validationEventHandler)
1122 {
1124 if (_source.NodeType == XmlNodeType.Document)
1125 {
1127 }
1128 else
1129 {
1131 if (schemas != null)
1132 {
1134 }
1135 }
1136 if (schemas == null && xmlDocument != null)
1137 {
1138 schemas = xmlDocument.Schemas;
1139 }
1140 if (schemas == null || schemas.Count == 0)
1141 {
1143 }
1146 return documentSchemaValidator.Validate(_source);
1147 }
1148
1150 {
1151 XmlNode parentNode = node.ParentNode;
1152 if (parentNode != null)
1153 {
1154 return parentNode;
1155 }
1157 {
1158 return xmlAttribute.OwnerElement;
1159 }
1160 return null;
1161 }
1162
1163 private static int GetDepth(XmlNode node)
1164 {
1165 int num = 0;
1167 {
1168 num++;
1169 }
1170 return num;
1171 }
1172
1174 {
1175 if (node1.XPNodeType == XPathNodeType.Attribute)
1176 {
1177 if (node2.XPNodeType == XPathNodeType.Attribute)
1178 {
1179 XmlElement ownerElement = ((XmlAttribute)node1).OwnerElement;
1180 if (ownerElement.HasAttributes)
1181 {
1182 XmlAttributeCollection attributes = ownerElement.Attributes;
1183 for (int i = 0; i < attributes.Count; i++)
1184 {
1185 XmlAttribute xmlAttribute = attributes[i];
1186 if (xmlAttribute == node1)
1187 {
1188 return XmlNodeOrder.Before;
1189 }
1190 if (xmlAttribute == node2)
1191 {
1192 return XmlNodeOrder.After;
1193 }
1194 }
1195 }
1196 return XmlNodeOrder.Unknown;
1197 }
1198 return XmlNodeOrder.Before;
1199 }
1200 if (node2.XPNodeType == XPathNodeType.Attribute)
1201 {
1202 return XmlNodeOrder.After;
1203 }
1204 XmlNode nextSibling = node1.NextSibling;
1205 while (nextSibling != null && nextSibling != node2)
1206 {
1207 nextSibling = nextSibling.NextSibling;
1208 }
1209 if (nextSibling == null)
1210 {
1211 return XmlNodeOrder.After;
1212 }
1213 return XmlNodeOrder.Before;
1214 }
1215
1217 {
1219 {
1220 return XmlNodeOrder.Unknown;
1221 }
1222 CalibrateText();
1223 documentXPathNavigator.CalibrateText();
1224 if (_source == documentXPathNavigator._source && _namespaceParent == documentXPathNavigator._namespaceParent)
1225 {
1226 return XmlNodeOrder.Same;
1227 }
1228 if (_namespaceParent != null || documentXPathNavigator._namespaceParent != null)
1229 {
1230 return base.ComparePosition(other);
1231 }
1236 if (xmlNode3 == xmlNode4)
1237 {
1238 if (xmlNode3 == null)
1239 {
1240 return XmlNodeOrder.Unknown;
1241 }
1242 return Compare(xmlNode, xmlNode2);
1243 }
1244 int num = GetDepth(xmlNode);
1245 int num2 = GetDepth(xmlNode2);
1246 if (num2 > num)
1247 {
1248 while (xmlNode2 != null && num2 > num)
1249 {
1251 num2--;
1252 }
1253 if (xmlNode == xmlNode2)
1254 {
1255 return XmlNodeOrder.Before;
1256 }
1258 }
1259 else if (num > num2)
1260 {
1261 while (xmlNode != null && num > num2)
1262 {
1264 num--;
1265 }
1266 if (xmlNode == xmlNode2)
1267 {
1268 return XmlNodeOrder.After;
1269 }
1271 }
1272 while (xmlNode3 != null && xmlNode4 != null)
1273 {
1274 if (xmlNode3 == xmlNode4)
1275 {
1276 return Compare(xmlNode, xmlNode2);
1277 }
1278 xmlNode = xmlNode3;
1282 }
1283 return XmlNodeOrder.Unknown;
1284 }
1285
1287 {
1288 return _source;
1289 }
1290
1291 public override XPathNodeIterator SelectDescendants(string localName, string namespaceURI, bool matchSelf)
1292 {
1294 if (text == null || _source.NodeType == XmlNodeType.Attribute)
1295 {
1296 return new DocumentXPathNodeIterator_Empty(this);
1297 }
1298 string text2 = _document.NameTable.Get(localName);
1299 if (text2 == null)
1300 {
1301 return new DocumentXPathNodeIterator_Empty(this);
1302 }
1303 if (text2.Length == 0)
1304 {
1305 if (matchSelf)
1306 {
1308 }
1310 }
1311 if (matchSelf)
1312 {
1314 }
1316 }
1317
1319 {
1320 if (nt == XPathNodeType.Element)
1321 {
1322 XmlNodeType nodeType = _source.NodeType;
1323 if (nodeType != XmlNodeType.Document && nodeType != XmlNodeType.Element)
1324 {
1325 return new DocumentXPathNodeIterator_Empty(this);
1326 }
1327 if (includeSelf)
1328 {
1330 }
1332 }
1333 return base.SelectDescendants(nt, includeSelf);
1334 }
1335
1336 public override XmlWriter PrependChild()
1337 {
1338 XmlNodeType nodeType = _source.NodeType;
1339 if (nodeType != XmlNodeType.Element && nodeType != XmlNodeType.Document && nodeType != XmlNodeType.DocumentFragment)
1340 {
1342 }
1346 }
1347
1348 public override XmlWriter AppendChild()
1349 {
1350 XmlNodeType nodeType = _source.NodeType;
1351 if (nodeType != XmlNodeType.Element && nodeType != XmlNodeType.Document && nodeType != XmlNodeType.DocumentFragment)
1352 {
1354 }
1358 }
1359
1360 public override XmlWriter InsertAfter()
1361 {
1363 switch (xmlNode.NodeType)
1364 {
1365 case XmlNodeType.Attribute:
1366 case XmlNodeType.Document:
1367 case XmlNodeType.DocumentFragment:
1369 case XmlNodeType.Text:
1370 case XmlNodeType.CDATA:
1371 case XmlNodeType.Whitespace:
1372 case XmlNodeType.SignificantWhitespace:
1374 break;
1375 }
1379 }
1380
1381 public override XmlWriter InsertBefore()
1382 {
1383 switch (_source.NodeType)
1384 {
1385 case XmlNodeType.Attribute:
1386 case XmlNodeType.Document:
1387 case XmlNodeType.DocumentFragment:
1389 case XmlNodeType.Text:
1390 case XmlNodeType.CDATA:
1391 case XmlNodeType.Whitespace:
1392 case XmlNodeType.SignificantWhitespace:
1393 CalibrateText();
1394 break;
1395 }
1399 }
1400
1411
1413 {
1415 {
1416 if (lastSiblingToReplace == null)
1417 {
1418 throw new ArgumentNullException("lastSiblingToReplace");
1419 }
1420 throw new NotSupportedException();
1421 }
1422 CalibrateText();
1423 documentXPathNavigator.CalibrateText();
1426 if (source == xmlNode)
1427 {
1428 switch (source.NodeType)
1429 {
1430 case XmlNodeType.Attribute:
1431 case XmlNodeType.Document:
1432 case XmlNodeType.DocumentFragment:
1434 case XmlNodeType.Text:
1435 case XmlNodeType.CDATA:
1436 case XmlNodeType.Whitespace:
1437 case XmlNodeType.SignificantWhitespace:
1439 break;
1440 }
1441 }
1442 else
1443 {
1444 if (xmlNode.IsText)
1445 {
1447 }
1449 {
1451 }
1452 }
1458 }
1459
1461 {
1463 {
1464 if (lastSiblingToDelete == null)
1465 {
1466 throw new ArgumentNullException("lastSiblingToDelete");
1467 }
1468 throw new NotSupportedException();
1469 }
1470 CalibrateText();
1471 documentXPathNavigator.CalibrateText();
1474 if (source == xmlNode)
1475 {
1476 switch (source.NodeType)
1477 {
1478 case XmlNodeType.Attribute:
1479 {
1481 if (!xmlAttribute.IsNamespace)
1482 {
1485 if (xmlNode2 != null)
1486 {
1488 }
1489 break;
1490 }
1491 goto default;
1492 }
1493 case XmlNodeType.Text:
1494 case XmlNodeType.CDATA:
1495 case XmlNodeType.Whitespace:
1496 case XmlNodeType.SignificantWhitespace:
1498 goto case XmlNodeType.Element;
1499 case XmlNodeType.Element:
1500 case XmlNodeType.ProcessingInstruction:
1501 case XmlNodeType.Comment:
1502 {
1505 if (xmlNode2 != null)
1506 {
1508 }
1509 break;
1510 }
1511 default:
1513 }
1514 }
1515 else
1516 {
1517 if (xmlNode.IsText)
1518 {
1520 }
1522 {
1524 }
1527 if (xmlNode3 != null)
1528 {
1530 }
1531 }
1532 }
1533
1534 public override void DeleteSelf()
1535 {
1537 XmlNode end = source;
1538 switch (source.NodeType)
1539 {
1540 case XmlNodeType.Attribute:
1541 {
1543 if (!xmlAttribute.IsNamespace)
1544 {
1547 if (xmlNode != null)
1548 {
1550 }
1551 break;
1552 }
1553 goto default;
1554 }
1555 case XmlNodeType.Text:
1556 case XmlNodeType.CDATA:
1557 case XmlNodeType.Whitespace:
1558 case XmlNodeType.SignificantWhitespace:
1559 CalibrateText();
1560 source = _source;
1561 end = TextEnd(source);
1562 goto case XmlNodeType.Element;
1563 case XmlNodeType.Element:
1564 case XmlNodeType.ProcessingInstruction:
1565 case XmlNodeType.Comment:
1566 {
1569 if (xmlNode != null)
1570 {
1572 }
1573 break;
1574 }
1575 default:
1577 }
1578 }
1579
1581 {
1583 {
1585 }
1587 {
1589 }
1590 attributes.RemoveAt(index);
1591 }
1592
1594 {
1595 XmlNode parentNode = node.ParentNode;
1596 if (parentNode == null)
1597 {
1599 }
1600 if (node.IsReadOnly || end.IsReadOnly)
1601 {
1603 }
1604 while (node != end)
1605 {
1607 node = node.NextSibling;
1608 parentNode.RemoveChild(oldChild);
1609 }
1610 parentNode.RemoveChild(node);
1611 }
1612
1614 {
1617 while (node != null)
1618 {
1620 {
1621 list.Add(xmlElement);
1622 }
1623 node = node.ParentNode;
1624 }
1625 for (int num = list.Count - 1; num >= 0; num--)
1626 {
1627 xmlNamespaceManager.PushScope();
1628 XmlAttributeCollection attributes = list[num].Attributes;
1629 for (int i = 0; i < attributes.Count; i++)
1630 {
1631 XmlAttribute xmlAttribute = attributes[i];
1632 if (xmlAttribute.IsNamespace)
1633 {
1634 string prefix = ((xmlAttribute.Prefix.Length == 0) ? string.Empty : xmlAttribute.LocalName);
1635 xmlNamespaceManager.AddNamespace(prefix, xmlAttribute.Value);
1636 }
1637 }
1638 }
1639 return xmlNamespaceManager;
1640 }
1641
1642 [MemberNotNull("_source")]
1644 {
1645 _source = node;
1647 {
1648 return;
1649 }
1650 XmlElement ownerElement = xmlAttribute.OwnerElement;
1651 if (ownerElement != null)
1652 {
1654 if (xmlAttribute.IsNamespace)
1655 {
1657 }
1658 }
1659 }
1660
1662 {
1663 if (attributes != null)
1664 {
1665 for (int i = 0; i < attributes.Count; i++)
1666 {
1667 if (attribute == attributes[i])
1668 {
1669 index = i;
1670 return true;
1671 }
1672 }
1673 }
1674 index = 0;
1675 return false;
1676 }
1677
1679 {
1680 XmlElement ownerElement = attribute.OwnerElement;
1681 if (ownerElement != null)
1682 {
1683 attributes = ownerElement.Attributes;
1684 if (index >= 0 && index < attributes.Count && attribute == attributes[index])
1685 {
1686 return true;
1687 }
1688 }
1689 else
1690 {
1691 attributes = null;
1692 }
1693 return false;
1694 }
1695
1696 private void CalibrateText()
1697 {
1699 {
1701 }
1702 }
1703
1705 {
1706 XmlNode parentNode = node.ParentNode;
1708 {
1709 return parentNode;
1710 }
1711 return ParentNodeTail(parentNode);
1712 }
1713
1715 {
1716 while (parent != null && parent.NodeType == XmlNodeType.EntityReference)
1717 {
1718 parent = parent.ParentNode;
1719 }
1720 return parent;
1721 }
1722
1724 {
1725 XmlNode firstChild = node.FirstChild;
1727 {
1728 return firstChild;
1729 }
1730 return FirstChildTail(firstChild);
1731 }
1732
1734 {
1735 while (child != null && child.NodeType == XmlNodeType.EntityReference)
1736 {
1737 child = child.FirstChild;
1738 }
1739 return child;
1740 }
1741
1743 {
1744 XmlNode nextSibling = node.NextSibling;
1746 {
1747 return nextSibling;
1748 }
1750 }
1751
1753 {
1755 while (sibling == null)
1756 {
1757 xmlNode = xmlNode.ParentNode;
1758 if (xmlNode == null || xmlNode.NodeType != XmlNodeType.EntityReference)
1759 {
1760 return null;
1761 }
1762 sibling = xmlNode.NextSibling;
1763 }
1764 while (sibling != null && sibling.NodeType == XmlNodeType.EntityReference)
1765 {
1766 sibling = sibling.FirstChild;
1767 }
1768 return sibling;
1769 }
1770
1772 {
1773 XmlNode previousSibling = node.PreviousSibling;
1775 {
1776 return previousSibling;
1777 }
1779 }
1780
1782 {
1784 while (sibling == null)
1785 {
1786 xmlNode = xmlNode.ParentNode;
1787 if (xmlNode == null || xmlNode.NodeType != XmlNodeType.EntityReference)
1788 {
1789 return null;
1790 }
1791 sibling = xmlNode.PreviousSibling;
1792 }
1793 while (sibling != null && sibling.NodeType == XmlNodeType.EntityReference)
1794 {
1795 sibling = sibling.LastChild;
1796 }
1797 return sibling;
1798 }
1799
1801 {
1802 XmlNode previousText = node.PreviousText;
1804 {
1805 return previousText;
1806 }
1808 }
1809
1811 {
1812 if (text != null)
1813 {
1814 return text;
1815 }
1816 if (!node.IsText)
1817 {
1818 return null;
1819 }
1820 XmlNode xmlNode = node.PreviousSibling;
1822 while (xmlNode == null)
1823 {
1824 xmlNode2 = xmlNode2.ParentNode;
1825 if (xmlNode2 == null || xmlNode2.NodeType != XmlNodeType.EntityReference)
1826 {
1827 return null;
1828 }
1829 xmlNode = xmlNode2.PreviousSibling;
1830 }
1831 while (xmlNode != null)
1832 {
1833 switch (xmlNode.NodeType)
1834 {
1835 case XmlNodeType.EntityReference:
1836 break;
1837 case XmlNodeType.Text:
1838 case XmlNodeType.CDATA:
1839 case XmlNodeType.Whitespace:
1840 case XmlNodeType.SignificantWhitespace:
1841 return xmlNode;
1842 default:
1843 return null;
1844 }
1845 xmlNode = xmlNode.LastChild;
1846 }
1847 return null;
1848 }
1849
1850 internal static bool IsFollowingSibling(XmlNode left, [NotNullWhen(true)] XmlNode right)
1851 {
1852 XmlNode xmlNode = left;
1853 while (true)
1854 {
1855 xmlNode = xmlNode.NextSibling;
1856 if (xmlNode == null)
1857 {
1858 break;
1859 }
1860 if (xmlNode == right)
1861 {
1862 return true;
1863 }
1864 }
1865 return false;
1866 }
1867
1868 private static bool IsDescendant(XmlNode top, XmlNode bottom)
1869 {
1870 while (true)
1871 {
1872 XmlNode xmlNode = bottom.ParentNode;
1873 if (xmlNode == null)
1874 {
1875 if (!(bottom is XmlAttribute xmlAttribute))
1876 {
1877 break;
1878 }
1879 xmlNode = xmlAttribute.OwnerElement;
1880 if (xmlNode == null)
1881 {
1882 break;
1883 }
1884 }
1885 bottom = xmlNode;
1886 if (top == bottom)
1887 {
1888 return true;
1889 }
1890 }
1891 return false;
1892 }
1893
1894 private static bool IsValidChild(XmlNode parent, XmlNode child)
1895 {
1896 switch (parent.NodeType)
1897 {
1898 case XmlNodeType.Element:
1899 return true;
1900 case XmlNodeType.DocumentFragment:
1901 switch (child.NodeType)
1902 {
1903 case XmlNodeType.Element:
1904 case XmlNodeType.Text:
1905 case XmlNodeType.CDATA:
1906 case XmlNodeType.ProcessingInstruction:
1907 case XmlNodeType.Comment:
1908 case XmlNodeType.Whitespace:
1909 case XmlNodeType.SignificantWhitespace:
1910 return true;
1911 }
1912 break;
1913 case XmlNodeType.Document:
1914 {
1915 XmlNodeType nodeType = child.NodeType;
1916 if (nodeType == XmlNodeType.Element || (uint)(nodeType - 7) <= 1u)
1917 {
1918 return true;
1919 }
1920 break;
1921 }
1922 }
1923 return false;
1924 }
1925
1927 {
1929 XmlNode result;
1930 do
1931 {
1932 result = xmlNode;
1934 }
1935 while (xmlNode != null && xmlNode.IsText);
1936 return result;
1937 }
1938
1940 {
1942 XmlNode result;
1943 do
1944 {
1945 result = xmlNode;
1947 }
1948 while (xmlNode != null && xmlNode.IsText);
1949 return result;
1950 }
1951}
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Xpn_MissingParent
Definition SR.cs:1318
static string Xdom_Node_Modify_ReadOnly
Definition SR.cs:1344
static string XmlDocument_NoSchemaInfo
Definition SR.cs:1178
static string Xpn_BadPosition
Definition SR.cs:1316
static string XPathDocument_SchemaSetNotAllowed
Definition SR.cs:1360
Definition SR.cs:7
override bool MoveToChild(string localName, string namespaceUri)
static bool MoveToNextNamespaceLocal(XmlAttributeCollection attributes, ref int index)
override bool IsDescendant([NotNullWhen(true)] XPathNavigator other)
static bool IsDescendant(XmlNode top, XmlNode bottom)
static bool ResetAttributePosition(XmlAttribute attribute, [NotNullWhen(true)] XmlAttributeCollection attributes, out int index)
override bool MoveToFollowing(string localName, string namespaceUri, XPathNavigator end)
static XmlNode OwnerNode(XmlNode node)
override XPathNodeIterator SelectDescendants(XPathNodeType nt, bool includeSelf)
static void DeleteToFollowingSibling(XmlNode node, XmlNode end)
XmlNodeOrder Compare(XmlNode node1, XmlNode node2)
override bool CheckValidity(XmlSchemaSet schemas, ValidationEventHandler validationEventHandler)
XmlNode NextSiblingTail(XmlNode node, XmlNode sibling)
override bool MoveToNextNamespace(XPathNamespaceScope scope)
override bool MoveTo(XPathNavigator other)
override XPathNodeIterator SelectDescendants(string localName, string namespaceURI, bool matchSelf)
static bool MoveToNextNamespaceGlobal(ref XmlAttributeCollection attributes, ref int index)
static bool IsFollowingSibling(XmlNode left, [NotNullWhen(true)] XmlNode right)
override bool IsSamePosition(XPathNavigator other)
DocumentXPathNavigator(DocumentXPathNavigator other)
override bool MoveToChild(XPathNodeType type)
override string GetAttribute(string localName, string namespaceURI)
static bool IsValidChild(XmlNode parent, XmlNode child)
static bool MoveToFirstNamespaceLocal(XmlAttributeCollection attributes, ref int index)
override XmlNodeOrder ComparePosition(XPathNavigator other)
override bool MoveToFirstNamespace(XPathNamespaceScope scope)
override bool MoveToNext(string localName, string namespaceUri)
override string LookupNamespace(string prefix)
override string GetNamespace(string name)
static bool CheckAttributePosition(XmlAttribute attribute, [NotNullWhen(true)] out XmlAttributeCollection attributes, int index)
override XmlWriter ReplaceRange(XPathNavigator lastSiblingToReplace)
static void DeleteAttribute(XmlAttribute attribute, int index)
override bool MoveToNamespace(string name)
override bool MoveToNext(XPathNodeType type)
static XmlNamespaceManager GetNamespaceManager(XmlNode node, XmlDocument document)
XmlNode PreviousSiblingTail(XmlNode node, XmlNode sibling)
bool PathHasDuplicateNamespace(XmlElement top, XmlElement bottom, string localName)
XmlNode PreviousTextTail(XmlNode node, XmlNode text)
override bool MoveToFollowing(XPathNodeType type, XPathNavigator end)
override bool MoveToAttribute(string localName, string namespaceURI)
override void DeleteRange(XPathNavigator lastSiblingToDelete)
static bool MoveToFirstNamespaceGlobal(ref XmlAttributeCollection attributes, ref int index)
DocumentXPathNavigator(XmlDocument document, XmlNode node)
override string Add(string key)
Definition NameTable.cs:33
static bool Equal(string strA, string strB)
Definition Ref.cs:5
static int GetContentKindMask(XPathNodeType type)
XmlAttribute NamespaceXml
XmlElement? DocumentElement
virtual ? XmlElement GetElementById(string elementId)
string? Get(char[] array, int offset, int length)
virtual ? string Value
Definition XmlNode.cs:62
virtual string BaseURI
Definition XmlNode.cs:233
XmlDocument Document
Definition XmlNode.cs:253
virtual string InnerText
Definition XmlNode.cs:157
virtual ? XmlNode ParentNode
Definition XmlNode.cs:76
virtual IXmlSchemaInfo SchemaInfo
Definition XmlNode.cs:230
virtual bool IsReadOnly
Definition XmlNode.cs:154
virtual string XmlLang
Definition XmlNode.cs:322
virtual string NamespaceURI
Definition XmlNode.cs:139
virtual ? XmlDocument OwnerDocument
Definition XmlNode.cs:109
virtual string GetXPAttribute(string localName, string namespaceURI)
Definition XmlNode.cs:1269
virtual bool IsText
Definition XmlNode.cs:344
virtual XmlNode RemoveChild(XmlNode oldChild)
Definition XmlNode.cs:662
virtual ? XmlNode FirstChild
Definition XmlNode.cs:120
virtual string Prefix
Definition XmlNode.cs:142
virtual XPathNodeType XPNodeType
Definition XmlNode.cs:340
XmlNodeType NodeType
Definition XmlNode.cs:73
virtual string XPLocalName
Definition XmlNode.cs:342