Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XPathNavigatorReader.cs
Go to the documentation of this file.
3
4namespace System.Xml.XPath;
5
7{
8 private enum State
9 {
10 Initial,
11 Content,
14 AttrVal,
16 EOF,
17 Closed,
18 Error
19 }
20
22
23 private readonly XPathNavigator _navToRead;
24
25 private int _depth;
26
27 private State _state;
28
30
31 private int _attrCount;
32
33 private bool _readEntireDocument;
34
36
38
40
42
44 {
45 XmlNodeType.Document,
46 XmlNodeType.Element,
47 XmlNodeType.Attribute,
48 XmlNodeType.Attribute,
49 XmlNodeType.Text,
50 XmlNodeType.SignificantWhitespace,
51 XmlNodeType.Whitespace,
52 XmlNodeType.ProcessingInstruction,
53 XmlNodeType.Comment,
55 };
56
58
59 protected bool IsReading
60 {
61 get
62 {
63 if (_state > State.Initial)
64 {
65 return _state < State.EOF;
66 }
67 return false;
68 }
69 }
70
72
74
87
88 public override IXmlSchemaInfo SchemaInfo
89 {
90 get
91 {
92 if (_nodeType == XmlNodeType.Text)
93 {
94 return null;
95 }
96 return _nav.SchemaInfo;
97 }
98 }
99
100 public override Type ValueType => _nav.ValueType;
101
102 public override XmlNodeType NodeType => _nodeType;
103
104 public override string NamespaceURI
105 {
106 get
107 {
108 if (_nav.NodeType == XPathNodeType.Namespace)
109 {
110 return NameTable.Add("http://www.w3.org/2000/xmlns/");
111 }
112 if (NodeType == XmlNodeType.Text)
113 {
114 return string.Empty;
115 }
116 return _nav.NamespaceURI;
117 }
118 }
119
120 public override string LocalName
121 {
122 get
123 {
124 if (_nav.NodeType == XPathNodeType.Namespace && _nav.LocalName.Length == 0)
125 {
126 return NameTable.Add("xmlns");
127 }
128 if (NodeType == XmlNodeType.Text)
129 {
130 return string.Empty;
131 }
132 return _nav.LocalName;
133 }
134 }
135
136 public override string Prefix
137 {
138 get
139 {
140 if (_nav.NodeType == XPathNodeType.Namespace && _nav.LocalName.Length != 0)
141 {
142 return NameTable.Add("xmlns");
143 }
144 if (NodeType == XmlNodeType.Text)
145 {
146 return string.Empty;
147 }
148 return _nav.Prefix;
149 }
150 }
151
152 public override string BaseURI
153 {
154 get
155 {
156 if (_state == State.Initial)
157 {
158 return _navToRead.BaseURI;
159 }
160 return _nav.BaseURI;
161 }
162 }
163
164 public override bool IsEmptyElement => _nav.IsEmptyElement;
165
166 public override XmlSpace XmlSpace
167 {
168 get
169 {
171 do
172 {
173 if (xPathNavigator.MoveToAttribute("space", "http://www.w3.org/XML/1998/namespace"))
174 {
176 if (text == "default")
177 {
178 return XmlSpace.Default;
179 }
180 if (text == "preserve")
181 {
182 return XmlSpace.Preserve;
183 }
184 xPathNavigator.MoveToParent();
185 }
186 }
187 while (xPathNavigator.MoveToParent());
188 return XmlSpace.None;
189 }
190 }
191
192 public override string XmlLang => _nav.XmlLang;
193
194 public override bool HasValue
195 {
196 get
197 {
198 if (_nodeType != XmlNodeType.Element && _nodeType != XmlNodeType.Document && _nodeType != XmlNodeType.EndElement && _nodeType != 0)
199 {
200 return true;
201 }
202 return false;
203 }
204 }
205
206 public override string Value
207 {
208 get
209 {
210 if (_nodeType != XmlNodeType.Element && _nodeType != XmlNodeType.Document && _nodeType != XmlNodeType.EndElement && _nodeType != 0)
211 {
212 return _nav.Value;
213 }
214 return string.Empty;
215 }
216 }
217
218 public override int AttributeCount
219 {
220 get
221 {
222 if (_attrCount < 0)
223 {
225 int num = 0;
226 if (elemNav != null)
227 {
228 if (elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local))
229 {
230 do
231 {
232 num++;
233 }
234 while (elemNav.MoveToNextNamespace(XPathNamespaceScope.Local));
235 elemNav.MoveToParent();
236 }
237 if (elemNav.MoveToFirstAttribute())
238 {
239 do
240 {
241 num++;
242 }
243 while (elemNav.MoveToNextAttribute());
244 }
245 }
246 _attrCount = num;
247 }
248 return _attrCount;
249 }
250 }
251
252 public override bool EOF => _state == State.EOF;
253
254 public override ReadState ReadState
255 {
256 get
257 {
258 switch (_state)
259 {
260 case State.Initial:
261 return ReadState.Initial;
262 case State.Content:
263 case State.EndElement:
264 case State.Attribute:
265 case State.AttrVal:
266 case State.InReadBinary:
267 return ReadState.Interactive;
268 case State.EOF:
269 return ReadState.EndOfFile;
270 case State.Closed:
271 return ReadState.Closed;
272 default:
273 return ReadState.Error;
274 }
275 }
276 }
277
278 public override bool CanReadBinaryContent => true;
279
280 public override int Depth => _depth;
281
283 {
284 return convertFromXPathNodeType[(int)typ];
285 }
286
298
309
314
319
324
326 {
327 switch (_state)
328 {
329 case State.Content:
330 return _nav.Clone();
331 case State.Attribute:
332 case State.AttrVal:
333 {
335 if (xPathNavigator.MoveToParent())
336 {
337 return xPathNavigator;
338 }
339 break;
340 }
341 case State.InReadBinary:
342 {
345 _state = State.InReadBinary;
346 return elemNav;
347 }
348 }
349 return null;
350 }
351
352 private XPathNavigator GetElemNav(out int depth)
353 {
355 switch (_state)
356 {
357 case State.Content:
358 if (_nodeType == XmlNodeType.Element)
359 {
361 }
362 depth = _depth;
363 break;
364 case State.Attribute:
366 xPathNavigator.MoveToParent();
367 depth = _depth - 1;
368 break;
369 case State.AttrVal:
371 xPathNavigator.MoveToParent();
372 depth = _depth - 2;
373 break;
374 case State.InReadBinary:
377 _state = State.InReadBinary;
378 break;
379 default:
380 depth = _depth;
381 break;
382 }
383 return xPathNavigator;
384 }
385
386 private void MoveToAttr(XPathNavigator nav, int depth)
387 {
388 _nav.MoveTo(nav);
389 _depth = depth;
390 _nodeType = XmlNodeType.Attribute;
391 _state = State.Attribute;
392 }
393
394 public override string GetAttribute(string name)
395 {
397 switch (xPathNavigator.NodeType)
398 {
399 case XPathNodeType.Attribute:
401 if (!xPathNavigator.MoveToParent())
402 {
403 return null;
404 }
405 break;
406 default:
407 return null;
408 case XPathNodeType.Element:
409 break;
410 }
412 if (prefix.Length == 0)
413 {
414 if (lname == "xmlns")
415 {
416 return xPathNavigator.GetNamespace(string.Empty);
417 }
418 if (xPathNavigator == _nav)
419 {
421 }
422 if (xPathNavigator.MoveToAttribute(lname, string.Empty))
423 {
424 return xPathNavigator.Value;
425 }
426 }
427 else
428 {
429 if (prefix == "xmlns")
430 {
431 return xPathNavigator.GetNamespace(lname);
432 }
433 if (xPathNavigator == _nav)
434 {
436 }
437 if (xPathNavigator.MoveToFirstAttribute())
438 {
439 do
440 {
441 if (xPathNavigator.LocalName == lname && xPathNavigator.Prefix == prefix)
442 {
443 return xPathNavigator.Value;
444 }
445 }
446 while (xPathNavigator.MoveToNextAttribute());
447 }
448 }
449 return null;
450 }
451
452 public override string GetAttribute(string localName, string namespaceURI)
453 {
454 if (localName == null)
455 {
456 throw new ArgumentNullException("localName");
457 }
459 switch (xPathNavigator.NodeType)
460 {
461 case XPathNodeType.Attribute:
463 if (!xPathNavigator.MoveToParent())
464 {
465 return null;
466 }
467 break;
468 default:
469 return null;
470 case XPathNodeType.Element:
471 break;
472 }
473 if (namespaceURI == "http://www.w3.org/2000/xmlns/")
474 {
475 if (localName == "xmlns")
476 {
477 localName = string.Empty;
478 }
479 return xPathNavigator.GetNamespace(localName);
480 }
481 if (namespaceURI == null)
482 {
483 namespaceURI = string.Empty;
484 }
485 if (xPathNavigator == _nav)
486 {
488 }
489 if (xPathNavigator.MoveToAttribute(localName, namespaceURI))
490 {
491 return xPathNavigator.Value;
492 }
493 return null;
494 }
495
496 private static string GetNamespaceByIndex(XPathNavigator nav, int index, out int count)
497 {
498 string value = nav.Value;
499 string result = null;
501 {
502 result = GetNamespaceByIndex(nav, index, out count);
503 }
504 else
505 {
506 count = 0;
507 }
508 if (count == index)
509 {
510 result = value;
511 }
512 count++;
513 return result;
514 }
515
516 public override string GetAttribute(int index)
517 {
518 if (index >= 0)
519 {
521 if (elemNav != null)
522 {
523 if (elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local))
524 {
525 int count;
527 if (namespaceByIndex != null)
528 {
529 return namespaceByIndex;
530 }
531 index -= count;
532 elemNav.MoveToParent();
533 }
534 if (elemNav.MoveToFirstAttribute())
535 {
536 do
537 {
538 if (index == 0)
539 {
540 return elemNav.Value;
541 }
542 index--;
543 }
544 while (elemNav.MoveToNextAttribute());
545 }
546 }
547 }
548 throw new ArgumentOutOfRangeException("index");
549 }
550
551 public override bool MoveToAttribute(string localName, string namespaceName)
552 {
553 if (localName == null)
554 {
555 throw new ArgumentNullException("localName");
556 }
557 int depth = _depth;
559 if (elemNav != null)
560 {
561 if (namespaceName == "http://www.w3.org/2000/xmlns/")
562 {
563 if (localName == "xmlns")
564 {
565 localName = string.Empty;
566 }
567 if (!elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local))
568 {
569 goto IL_0078;
570 }
571 while (!(elemNav.LocalName == localName))
572 {
573 if (elemNav.MoveToNextNamespace(XPathNamespaceScope.Local))
574 {
575 continue;
576 }
577 goto IL_0078;
578 }
579 }
580 else
581 {
582 if (namespaceName == null)
583 {
584 namespaceName = string.Empty;
585 }
586 if (!elemNav.MoveToAttribute(localName, namespaceName))
587 {
588 goto IL_0078;
589 }
590 }
591 if (_state == State.InReadBinary)
592 {
595 }
596 MoveToAttr(elemNav, depth + 1);
597 return true;
598 }
599 goto IL_0078;
600 IL_0078:
601 return false;
602 }
603
604 public override bool MoveToFirstAttribute()
605 {
606 int depth;
608 if (elemNav != null)
609 {
610 if (elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local))
611 {
612 while (elemNav.MoveToNextNamespace(XPathNamespaceScope.Local))
613 {
614 }
615 }
616 else if (!elemNav.MoveToFirstAttribute())
617 {
618 goto IL_0028;
619 }
620 if (_state == State.InReadBinary)
621 {
624 }
625 MoveToAttr(elemNav, depth + 1);
626 return true;
627 }
628 goto IL_0028;
629 IL_0028:
630 return false;
631 }
632
633 public override bool MoveToNextAttribute()
634 {
635 switch (_state)
636 {
637 case State.Content:
638 return MoveToFirstAttribute();
639 case State.Attribute:
640 {
641 if (XPathNodeType.Attribute == _nav.NodeType)
642 {
643 return _nav.MoveToNextAttribute();
644 }
646 if (!xPathNavigator.MoveToParent())
647 {
648 return false;
649 }
650 if (!xPathNavigator.MoveToFirstNamespace(XPathNamespaceScope.Local))
651 {
652 return false;
653 }
654 if (xPathNavigator.IsSamePosition(_nav))
655 {
656 xPathNavigator.MoveToParent();
657 if (!xPathNavigator.MoveToFirstAttribute())
658 {
659 return false;
660 }
662 return true;
663 }
665 while (true)
666 {
667 if (!xPathNavigator.MoveToNextNamespace(XPathNamespaceScope.Local))
668 {
669 return false;
670 }
671 if (xPathNavigator.IsSamePosition(_nav))
672 {
673 break;
674 }
676 }
678 return true;
679 }
680 case State.AttrVal:
681 _depth--;
682 _state = State.Attribute;
683 if (!MoveToNextAttribute())
684 {
685 _depth++;
686 _state = State.AttrVal;
687 return false;
688 }
689 _nodeType = XmlNodeType.Attribute;
690 return true;
691 case State.InReadBinary:
693 if (!MoveToNextAttribute())
694 {
695 _state = State.InReadBinary;
696 return false;
697 }
699 return true;
700 default:
701 return false;
702 }
703 }
704
705 public override bool MoveToAttribute(string name)
706 {
707 int depth;
709 if (elemNav == null)
710 {
711 return false;
712 }
714 bool flag = false;
715 if ((flag = prefix.Length == 0 && lname == "xmlns") || prefix == "xmlns")
716 {
717 if (flag)
718 {
719 lname = string.Empty;
720 }
721 if (!elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local))
722 {
723 goto IL_00b3;
724 }
725 while (!(elemNav.LocalName == lname))
726 {
727 if (elemNav.MoveToNextNamespace(XPathNamespaceScope.Local))
728 {
729 continue;
730 }
731 goto IL_00b3;
732 }
733 }
734 else if (prefix.Length == 0)
735 {
736 if (!elemNav.MoveToAttribute(lname, string.Empty))
737 {
738 goto IL_00b3;
739 }
740 }
741 else
742 {
743 if (!elemNav.MoveToFirstAttribute())
744 {
745 goto IL_00b3;
746 }
747 while (!(elemNav.LocalName == lname) || !(elemNav.Prefix == prefix))
748 {
749 if (elemNav.MoveToNextAttribute())
750 {
751 continue;
752 }
753 goto IL_00b3;
754 }
755 }
756 if (_state == State.InReadBinary)
757 {
760 }
761 MoveToAttr(elemNav, depth + 1);
762 return true;
763 IL_00b3:
764 return false;
765 }
766
767 public override bool MoveToElement()
768 {
769 switch (_state)
770 {
771 case State.Attribute:
772 case State.AttrVal:
773 if (!_nav.MoveToParent())
774 {
775 return false;
776 }
777 _depth--;
778 if (_state == State.AttrVal)
779 {
780 _depth--;
781 }
782 _state = State.Content;
783 _nodeType = XmlNodeType.Element;
784 return true;
785 case State.InReadBinary:
787 if (!MoveToElement())
788 {
789 _state = State.InReadBinary;
790 return false;
791 }
793 break;
794 }
795 return false;
796 }
797
798 public override void ResolveEntity()
799 {
801 }
802
803 public override bool ReadAttributeValue()
804 {
805 if (_state == State.InReadBinary)
806 {
809 }
810 if (_state == State.Attribute)
811 {
812 _state = State.AttrVal;
813 _nodeType = XmlNodeType.Text;
814 _depth++;
815 return true;
816 }
817 return false;
818 }
819
820 public override int ReadContentAsBase64(byte[] buffer, int index, int count)
821 {
822 if (ReadState != ReadState.Interactive)
823 {
824 return 0;
825 }
826 if (_state != State.InReadBinary)
827 {
830 }
834 _state = State.InReadBinary;
835 return result;
836 }
837
838 public override int ReadContentAsBinHex(byte[] buffer, int index, int count)
839 {
840 if (ReadState != ReadState.Interactive)
841 {
842 return 0;
843 }
844 if (_state != State.InReadBinary)
845 {
848 }
852 _state = State.InReadBinary;
853 return result;
854 }
855
856 public override int ReadElementContentAsBase64(byte[] buffer, int index, int count)
857 {
858 if (ReadState != ReadState.Interactive)
859 {
860 return 0;
861 }
862 if (_state != State.InReadBinary)
863 {
866 }
870 _state = State.InReadBinary;
871 return result;
872 }
873
874 public override int ReadElementContentAsBinHex(byte[] buffer, int index, int count)
875 {
876 if (ReadState != ReadState.Interactive)
877 {
878 return 0;
879 }
880 if (_state != State.InReadBinary)
881 {
884 }
888 _state = State.InReadBinary;
889 return result;
890 }
891
892 public override string LookupNamespace(string prefix)
893 {
895 }
896
897 public override bool Read()
898 {
899 _attrCount = -1;
900 switch (_state)
901 {
902 case State.EOF:
903 case State.Closed:
904 case State.Error:
905 return false;
906 case State.Initial:
908 _state = State.Content;
909 if (_nav.NodeType == XPathNodeType.Root)
910 {
911 if (!_nav.MoveToFirstChild())
912 {
913 SetEOF();
914 return false;
915 }
916 _readEntireDocument = true;
917 }
918 else if (XPathNodeType.Attribute == _nav.NodeType)
919 {
920 _state = State.Attribute;
921 }
923 break;
924 case State.Content:
926 {
928 _depth++;
929 _state = State.Content;
930 break;
931 }
932 if (_nodeType == XmlNodeType.Element && !_nav.IsEmptyElement)
933 {
934 _nodeType = XmlNodeType.EndElement;
935 _state = State.EndElement;
936 break;
937 }
938 goto case State.EndElement;
939 case State.EndElement:
940 if (_depth == 0 && !_readEntireDocument)
941 {
942 SetEOF();
943 return false;
944 }
945 if (_nav.MoveToNext())
946 {
948 _state = State.Content;
949 break;
950 }
951 if (_depth > 0 && _nav.MoveToParent())
952 {
953 _nodeType = XmlNodeType.EndElement;
954 _state = State.EndElement;
955 _depth--;
956 break;
957 }
958 SetEOF();
959 return false;
960 case State.Attribute:
961 case State.AttrVal:
962 if (!_nav.MoveToParent())
963 {
964 SetEOF();
965 return false;
966 }
968 _depth--;
969 if (_state == State.AttrVal)
970 {
971 _depth--;
972 }
973 goto case State.Content;
974 case State.InReadBinary:
977 return Read();
978 }
979 return true;
980 }
981
982 public override void Close()
983 {
985 _nodeType = XmlNodeType.None;
986 _state = State.Closed;
987 _depth = 0;
988 }
989
990 private void SetEOF()
991 {
993 _nodeType = XmlNodeType.None;
994 _state = State.EOF;
995 _depth = 0;
996 }
997}
static string Xml_InvalidOperation
Definition SR.cs:18
Definition SR.cs:7
override string Add(string key)
Definition NameTable.cs:33
static ReadContentAsBinaryHelper CreateOrReset(ReadContentAsBinaryHelper helper, XmlReader reader)
int ReadContentAsBase64(byte[] buffer, int index, int count)
int ReadContentAsBinHex(byte[] buffer, int index, int count)
int ReadElementContentAsBinHex(byte[] buffer, int index, int count)
int ReadElementContentAsBase64(byte[] buffer, int index, int count)
static void SplitQName(string name, out string prefix, out string lname)
override int ReadElementContentAsBinHex(byte[] buffer, int index, int count)
void MoveToAttr(XPathNavigator nav, int depth)
override string GetAttribute(string name)
ReadContentAsBinaryHelper _readBinaryHelper
override int ReadElementContentAsBase64(byte[] buffer, int index, int count)
XPathNavigatorReader(XPathNavigator navToRead, IXmlLineInfo xli, IXmlSchemaInfo xsi)
static string GetNamespaceByIndex(XPathNavigator nav, int index, out int count)
override bool MoveToAttribute(string localName, string namespaceName)
static XPathNavigatorReader Create(XPathNavigator navToRead)
override string LookupNamespace(string prefix)
XPathNavigator GetElemNav(out int depth)
static XmlNodeType ToXmlNodeType(XPathNodeType typ)
override string GetAttribute(string localName, string namespaceURI)
override int ReadContentAsBase64(byte[] buffer, int index, int count)
override XmlNamespaceManager NamespaceManager
override int ReadContentAsBinHex(byte[] buffer, int index, int count)
bool MoveTo(XPathNavigator other)
virtual IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
static XmlNamespaceManager GetNamespaces(IXmlNamespaceResolver resolver)
virtual ? string LookupPrefix(string namespaceURI)
bool MoveToNextNamespace(XPathNamespaceScope namespaceScope)
virtual ? string LookupNamespace(string prefix)
virtual ? IXmlSchemaInfo SchemaInfo
static XmlEmptyNavigator Singleton
static string TrimString(string value)
IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
string? LookupPrefix(string namespaceName)
string? LookupNamespace(string prefix)