Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlDocument.cs
Go to the documentation of this file.
5using System.IO;
6using System.Text;
9
10namespace System.Xml;
11
12public class XmlDocument : XmlNode
13{
14 private static readonly (string key, int hash)[] s_nameTableSeeds = new(string, int)[15]
15 {
16 ("#document", System.Xml.NameTable.ComputeHash32("#document")),
17 ("#document-fragment", System.Xml.NameTable.ComputeHash32("#document-fragment")),
18 ("#comment", System.Xml.NameTable.ComputeHash32("#comment")),
19 ("#text", System.Xml.NameTable.ComputeHash32("#text")),
20 ("#cdata-section", System.Xml.NameTable.ComputeHash32("#cdata-section")),
21 ("#entity", System.Xml.NameTable.ComputeHash32("#entity")),
22 ("id", System.Xml.NameTable.ComputeHash32("id")),
23 ("xmlns", System.Xml.NameTable.ComputeHash32("xmlns")),
24 ("xml", System.Xml.NameTable.ComputeHash32("xml")),
25 ("space", System.Xml.NameTable.ComputeHash32("space")),
26 ("lang", System.Xml.NameTable.ComputeHash32("lang")),
27 ("#whitespace", System.Xml.NameTable.ComputeHash32("#whitespace")),
28 ("#significant-whitespace", System.Xml.NameTable.ComputeHash32("#significant-whitespace")),
29 ("http://www.w3.org/2000/xmlns/", System.Xml.NameTable.ComputeHash32("http://www.w3.org/2000/xmlns/")),
30 ("http://www.w3.org/XML/1998/namespace", System.Xml.NameTable.ComputeHash32("http://www.w3.org/XML/1998/namespace"))
31 };
32
34
36
38
40
42
44
46
48
49 private bool _reportValidity;
50
52
53 private XmlNodeChangedEventHandler _onNodeInsertingDelegate;
54
55 private XmlNodeChangedEventHandler _onNodeInsertedDelegate;
56
57 private XmlNodeChangedEventHandler _onNodeRemovingDelegate;
58
59 private XmlNodeChangedEventHandler _onNodeRemovedDelegate;
60
61 private XmlNodeChangedEventHandler _onNodeChangingDelegate;
62
63 private XmlNodeChangedEventHandler _onNodeChangedDelegate;
64
65 internal bool fEntRefNodesPresent;
66
67 internal bool fCDataNodesPresent;
68
69 private bool _preserveWhitespace;
70
71 private bool _isLoading;
72
73 internal string strDocumentName;
74
75 internal string strDocumentFragmentName;
76
77 internal string strCommentName;
78
79 internal string strTextName;
80
81 internal string strCDataSectionName;
82
83 internal string strEntityName;
84
85 internal string strID;
86
87 internal string strXmlns;
88
89 internal string strXml;
90
91 internal string strSpace;
92
93 internal string strLang;
94
96
98
99 internal string strReservedXmlns;
100
101 internal string strReservedXml;
102
103 internal string baseURI;
104
106
107 internal bool bSetResolver;
108
109 internal object objLock;
110
112
114
116
118
120
122 {
123 get
124 {
125 return _schemaInfo;
126 }
127 set
128 {
130 }
131 }
132
133 public override XmlNodeType NodeType => XmlNodeType.Document;
134
135 public override XmlNode? ParentNode => null;
136
138
139 internal virtual XmlDeclaration? Declaration
140 {
141 get
142 {
143 if (HasChildNodes)
144 {
146 }
147 return null;
148 }
149 }
150
152
153 public override string Name => strDocumentName;
154
155 public override string LocalName => strDocumentName;
156
158
159 internal override bool IsContainer => true;
160
161 internal override XmlLinkedNode? LastNode
162 {
163 get
164 {
165 return _lastChild;
166 }
167 set
168 {
170 }
171 }
172
173 public override XmlDocument? OwnerDocument => null;
174
176 {
177 get
178 {
179 if (_schemas == null)
180 {
182 }
183 return _schemas;
184 }
185 set
186 {
187 _schemas = value;
188 }
189 }
190
192
193 internal bool HasSetResolver => bSetResolver;
194
195 public virtual XmlResolver? XmlResolver
196 {
197 set
198 {
200 if (!bSetResolver)
201 {
202 bSetResolver = true;
203 }
205 if (documentType != null)
206 {
208 }
209 }
210 }
211
213
215 {
216 get
217 {
218 return _preserveWhitespace;
219 }
220 set
221 {
223 }
224 }
225
226 public override bool IsReadOnly => false;
227
229 {
230 get
231 {
232 if (_entities == null)
233 {
234 _entities = new XmlNamedNodeMap(this);
235 }
236 return _entities;
237 }
238 set
239 {
241 }
242 }
243
244 internal bool IsLoading
245 {
246 get
247 {
248 return _isLoading;
249 }
250 set
251 {
253 }
254 }
255
257
259 {
260 get
261 {
262 if (Declaration != null)
263 {
264 string encoding = Declaration.Encoding;
265 if (encoding.Length > 0)
266 {
267 return System.Text.Encoding.GetEncoding(encoding);
268 }
269 }
270 return null;
271 }
272 }
273
274 public override string InnerText
275 {
277 set
278 {
280 }
281 }
282
283 public override string InnerXml
284 {
285 get
286 {
287 return base.InnerXml;
288 }
289 set
290 {
291 LoadXml(value);
292 }
293 }
294
295 internal string? Version => Declaration?.Version;
296
297 internal string? Encoding => Declaration?.Encoding;
298
299 internal string? Standalone => Declaration?.Standalone;
300
302 {
303 get
304 {
305 if (_reportValidity)
306 {
308 if (documentElement != null)
309 {
310 switch (documentElement.SchemaInfo.Validity)
311 {
312 case XmlSchemaValidity.Valid:
313 return ValidSchemaInfo;
314 case XmlSchemaValidity.Invalid:
315 return InvalidSchemaInfo;
316 }
317 }
318 }
319 return NotKnownSchemaInfo;
320 }
321 }
322
323 public override string BaseURI => baseURI;
324
325 internal override XPathNodeType XPNodeType => XPathNodeType.Root;
326
328
330 {
331 get
332 {
333 if (_namespaceXml == null)
334 {
337 }
338 return _namespaceXml;
339 }
340 }
341
353
365
377
389
401
413
414 public XmlDocument()
416 {
417 }
418
423
425 {
427 _domNameTable = new DomNameTable(this);
428 strXmlns = "xmlns";
429 strXml = "xml";
430 strReservedXmlns = "http://www.w3.org/2000/xmlns/";
431 strReservedXml = "http://www.w3.org/XML/1998/namespace";
432 baseURI = string.Empty;
433 objLock = new object();
434 if (imp.NameTable.GetType() == typeof(NameTable))
435 {
436 NameTable nameTable = (NameTable)imp.NameTable;
449 strLang = nameTable.GetOrAddEntry(s_nameTableSeeds[10].key, s_nameTableSeeds[10].hash);
452 }
453 else
454 {
455 XmlNameTable nameTable2 = imp.NameTable;
456 strDocumentName = nameTable2.Add("#document");
457 strDocumentFragmentName = nameTable2.Add("#document-fragment");
458 strCommentName = nameTable2.Add("#comment");
459 strTextName = nameTable2.Add("#text");
460 strCDataSectionName = nameTable2.Add("#cdata-section");
461 strEntityName = nameTable2.Add("#entity");
462 strID = nameTable2.Add("id");
464 strSignificantWhitespaceName = nameTable2.Add("#significant-whitespace");
465 strXmlns = nameTable2.Add("xmlns");
466 strXml = nameTable2.Add("xml");
467 strSpace = nameTable2.Add("space");
468 strLang = nameTable2.Add("lang");
469 strReservedXmlns = nameTable2.Add("http://www.w3.org/2000/xmlns/");
470 strReservedXml = nameTable2.Add("http://www.w3.org/XML/1998/namespace");
471 }
472 }
473
474 internal static void CheckName(string name)
475 {
476 int num = ValidateNames.ParseNmtoken(name, 0);
477 if (num < name.Length)
478 {
480 }
481 }
482
483 internal XmlName AddXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
484 {
485 return _domNameTable.AddName(prefix, localName, namespaceURI, schemaInfo);
486 }
487
488 internal XmlName GetXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
489 {
490 return _domNameTable.GetName(prefix, localName, namespaceURI, schemaInfo);
491 }
492
493 internal XmlName AddAttrXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
494 {
495 XmlName xmlName = AddXmlName(prefix, localName, namespaceURI, schemaInfo);
496 if (!IsLoading)
497 {
498 object prefix2 = xmlName.Prefix;
499 object namespaceURI2 = xmlName.NamespaceURI;
500 object localName2 = xmlName.LocalName;
501 if ((prefix2 == strXmlns || (xmlName.Prefix.Length == 0 && localName2 == strXmlns)) ^ (namespaceURI2 == strReservedXmlns))
502 {
504 }
505 }
506 return xmlName;
507 }
508
510 {
511 if (_htElementIDAttrDecl == null || _htElementIDAttrDecl[eleName] == null)
512 {
513 if (_htElementIDAttrDecl == null)
514 {
516 }
518 return true;
519 }
520 return false;
521 }
522
524 {
525 XmlName xmlName = GetXmlName(eleName.Prefix, eleName.LocalName, string.Empty, null);
526 if (xmlName != null)
527 {
529 }
530 return null;
531 }
532
534 {
535 if (_htElementIDAttrDecl == null)
536 {
537 return null;
538 }
540 }
541
543 {
545 foreach (WeakReference<XmlElement> element in elementList)
546 {
547 if (!element.TryGetTarget(out var target))
548 {
549 arrayList.Add(element);
550 }
551 else if (target == elem)
552 {
553 return element;
554 }
555 }
557 {
559 }
560 return null;
561 }
562
563 internal void AddElementWithId(string id, XmlElement elem)
564 {
565 if (_htElementIdMap == null || !_htElementIdMap.Contains(id))
566 {
567 if (_htElementIdMap == null)
568 {
570 }
574 }
575 else
576 {
578 if (GetElement(arrayList2, elem) == null)
579 {
581 }
582 }
583 }
584
585 internal void RemoveElementWithId(string id, XmlElement elem)
586 {
587 if (_htElementIdMap == null || !_htElementIdMap.Contains(id))
588 {
589 return;
590 }
593 if (element != null)
594 {
595 arrayList.Remove(element);
596 if (arrayList.Count == 0)
597 {
599 }
600 }
601 }
602
603 public override XmlNode CloneNode(bool deep)
604 {
606 xmlDocument.SetBaseURI(baseURI);
607 if (deep)
608 {
609 xmlDocument.ImportChildren(this, xmlDocument, deep);
610 }
611 return xmlDocument;
612 }
613
615 {
616 return _resolver;
617 }
618
619 internal override bool IsValidChildType(XmlNodeType type)
620 {
621 switch (type)
622 {
623 case XmlNodeType.ProcessingInstruction:
624 case XmlNodeType.Comment:
625 case XmlNodeType.Whitespace:
626 case XmlNodeType.SignificantWhitespace:
627 return true;
628 case XmlNodeType.DocumentType:
629 if (DocumentType != null)
630 {
632 }
633 return true;
634 case XmlNodeType.Element:
635 if (DocumentElement != null)
636 {
638 }
639 return true;
640 case XmlNodeType.XmlDeclaration:
641 if (Declaration != null)
642 {
644 }
645 return true;
646 default:
647 return false;
648 }
649 }
650
652 {
653 if (refNode == null)
654 {
655 return false;
656 }
657 XmlNode xmlNode = null;
658 if (refNode.ParentNode != null)
659 {
660 xmlNode = refNode.ParentNode.FirstChild;
661 }
662 while (xmlNode != null)
663 {
664 if (xmlNode.NodeType == nt)
665 {
666 return true;
667 }
668 if (xmlNode == refNode)
669 {
670 break;
671 }
672 xmlNode = xmlNode.NextSibling;
673 }
674 return false;
675 }
676
678 {
679 for (XmlNode xmlNode = refNode; xmlNode != null; xmlNode = xmlNode.NextSibling)
680 {
681 if (xmlNode.NodeType == nt)
682 {
683 return true;
684 }
685 }
686 return false;
687 }
688
690 {
691 if (refChild == null)
692 {
694 }
695 if (refChild == null)
696 {
697 return true;
698 }
699 switch (newChild.NodeType)
700 {
701 case XmlNodeType.XmlDeclaration:
702 return refChild == FirstChild;
703 case XmlNodeType.ProcessingInstruction:
704 case XmlNodeType.Comment:
705 return refChild.NodeType != XmlNodeType.XmlDeclaration;
706 case XmlNodeType.DocumentType:
707 if (refChild.NodeType != XmlNodeType.XmlDeclaration)
708 {
709 return !HasNodeTypeInPrevSiblings(XmlNodeType.Element, refChild.PreviousSibling);
710 }
711 break;
712 case XmlNodeType.Element:
713 if (refChild.NodeType != XmlNodeType.XmlDeclaration)
714 {
715 return !HasNodeTypeInNextSiblings(XmlNodeType.DocumentType, refChild);
716 }
717 break;
718 }
719 return false;
720 }
721
723 {
724 if (refChild == null)
725 {
727 }
728 if (refChild == null)
729 {
730 return true;
731 }
732 switch (newChild.NodeType)
733 {
734 case XmlNodeType.ProcessingInstruction:
735 case XmlNodeType.Comment:
736 case XmlNodeType.Whitespace:
737 case XmlNodeType.SignificantWhitespace:
738 return true;
739 case XmlNodeType.DocumentType:
741 case XmlNodeType.Element:
742 return !HasNodeTypeInNextSiblings(XmlNodeType.DocumentType, refChild.NextSibling);
743 default:
744 return false;
745 }
746 }
747
748 public XmlAttribute CreateAttribute(string name)
749 {
750 string prefix = string.Empty;
751 string localName = string.Empty;
752 string namespaceURI = string.Empty;
753 XmlNode.SplitName(name, out prefix, out localName);
755 return CreateAttribute(prefix, localName, namespaceURI);
756 }
757
758 internal void SetDefaultNamespace(string prefix, string localName, ref string namespaceURI)
759 {
760 if (prefix == strXmlns || (prefix.Length == 0 && localName == strXmlns))
761 {
763 }
764 else if (prefix == strXml)
765 {
767 }
768 }
769
770 public virtual XmlCDataSection CreateCDataSection(string? data)
771 {
772 fCDataNodesPresent = true;
773 return new XmlCDataSection(data, this);
774 }
775
776 public virtual XmlComment CreateComment(string? data)
777 {
778 return new XmlComment(data, this);
779 }
780
781 public virtual XmlDocumentType CreateDocumentType(string name, string? publicId, string? systemId, string? internalSubset)
782 {
783 return new XmlDocumentType(name, publicId, systemId, internalSubset, this);
784 }
785
787 {
788 return new XmlDocumentFragment(this);
789 }
790
791 public XmlElement CreateElement(string name)
792 {
793 string prefix = string.Empty;
794 string localName = string.Empty;
795 XmlNode.SplitName(name, out prefix, out localName);
796 return CreateElement(prefix, localName, string.Empty);
797 }
798
800 {
803 if (schemaElementDecl == null || schemaElementDecl.AttDefs == null)
804 {
805 return;
806 }
808 {
809 SchemaAttDef value = attDef.Value;
810 if (value.Presence == SchemaDeclBase.Use.Default || value.Presence == SchemaDeclBase.Use.Fixed)
811 {
812 string name = value.Name.Name;
813 string attrNamespaceURI = string.Empty;
814 string attrPrefix;
815 if (dtdSchemaInfo.SchemaType == SchemaType.DTD)
816 {
817 attrPrefix = value.Name.Namespace;
818 }
819 else
820 {
821 attrPrefix = value.Prefix;
822 attrNamespaceURI = value.Name.Namespace;
823 }
825 elem.SetAttributeNode(attributeNode);
826 }
827 }
828 }
829
831 {
833 if (dtdSchemaInfo != null)
834 {
835 XmlQualifiedName key = new XmlQualifiedName(elem.LocalName, (dtdSchemaInfo.SchemaType == SchemaType.DTD) ? elem.Prefix : elem.NamespaceURI);
836 if (dtdSchemaInfo.ElementDecls.TryGetValue(key, out var value))
837 {
838 return value;
839 }
840 }
841 return null;
842 }
843
855
856 public virtual XmlEntityReference CreateEntityReference(string name)
857 {
858 return new XmlEntityReference(name, this);
859 }
860
861 public virtual XmlProcessingInstruction CreateProcessingInstruction(string target, string data)
862 {
863 return new XmlProcessingInstruction(target, data, this);
864 }
865
866 public virtual XmlDeclaration CreateXmlDeclaration(string version, string? encoding, string? standalone)
867 {
868 return new XmlDeclaration(version, encoding, standalone, this);
869 }
870
871 public virtual XmlText CreateTextNode(string? text)
872 {
873 return new XmlText(text, this);
874 }
875
877 {
878 return new XmlSignificantWhitespace(text, this);
879 }
880
882 {
883 return CreateNavigator(this);
884 }
885
886 protected internal virtual XPathNavigator? CreateNavigator(XmlNode node)
887 {
888 switch (node.NodeType)
889 {
890 case XmlNodeType.EntityReference:
891 case XmlNodeType.Entity:
892 case XmlNodeType.DocumentType:
893 case XmlNodeType.Notation:
894 case XmlNodeType.XmlDeclaration:
895 return null;
896 case XmlNodeType.Text:
897 case XmlNodeType.CDATA:
898 case XmlNodeType.SignificantWhitespace:
899 {
900 XmlNode xmlNode = node.ParentNode;
901 if (xmlNode != null)
902 {
903 do
904 {
905 switch (xmlNode.NodeType)
906 {
907 case XmlNodeType.Attribute:
908 return null;
909 case XmlNodeType.EntityReference:
910 goto IL_006a;
911 }
912 break;
913 IL_006a:
914 xmlNode = xmlNode.ParentNode;
915 }
916 while (xmlNode != null);
917 }
919 break;
920 }
921 case XmlNodeType.Whitespace:
922 {
923 XmlNode xmlNode = node.ParentNode;
924 if (xmlNode != null)
925 {
926 do
927 {
928 switch (xmlNode.NodeType)
929 {
930 case XmlNodeType.Attribute:
931 case XmlNodeType.Document:
932 return null;
933 case XmlNodeType.EntityReference:
934 goto IL_009f;
935 }
936 break;
937 IL_009f:
938 xmlNode = xmlNode.ParentNode;
939 }
940 while (xmlNode != null);
941 }
943 break;
944 }
945 }
946 return new DocumentXPathNavigator(this, node);
947 }
948
949 internal static bool IsTextNode(XmlNodeType nt)
950 {
951 if ((uint)(nt - 3) <= 1u || (uint)(nt - 13) <= 1u)
952 {
953 return true;
954 }
955 return false;
956 }
957
959 {
960 XmlNode xmlNode = null;
962 while (IsTextNode(xmlNode2.NodeType))
963 {
965 xmlNode2 = xmlNode2.PreviousSibling;
966 if (xmlNode2 == null)
967 {
969 while (xmlNode3.ParentNode != null && xmlNode3.ParentNode.NodeType == XmlNodeType.EntityReference)
970 {
971 if (xmlNode3.ParentNode.PreviousSibling != null)
972 {
973 xmlNode2 = xmlNode3.ParentNode.PreviousSibling;
974 break;
975 }
976 xmlNode3 = xmlNode3.ParentNode;
977 if (xmlNode3 == null)
978 {
979 break;
980 }
981 }
982 }
983 if (xmlNode2 == null)
984 {
985 break;
986 }
987 while (xmlNode2.NodeType == XmlNodeType.EntityReference)
988 {
989 xmlNode2 = xmlNode2.LastChild;
990 }
991 }
992 return xmlNode;
993 }
994
995 public virtual XmlWhitespace CreateWhitespace(string? text)
996 {
997 return new XmlWhitespace(text, this);
998 }
999
1000 public virtual XmlNodeList GetElementsByTagName(string name)
1001 {
1002 return new XmlElementList(this, name);
1003 }
1004
1006 {
1007 string prefix = string.Empty;
1008 string localName = string.Empty;
1010 return CreateAttribute(prefix, localName, namespaceURI);
1011 }
1012
1014 {
1015 string prefix = string.Empty;
1016 string localName = string.Empty;
1018 return CreateElement(prefix, localName, namespaceURI);
1019 }
1020
1021 public virtual XmlNodeList GetElementsByTagName(string localName, string namespaceURI)
1022 {
1023 return new XmlElementList(this, localName, namespaceURI);
1024 }
1025
1026 public virtual XmlElement? GetElementById(string elementId)
1027 {
1028 if (_htElementIdMap != null)
1029 {
1031 if (arrayList != null)
1032 {
1034 {
1035 if (item.TryGetTarget(out var target) && target.IsConnected())
1036 {
1037 return target;
1038 }
1039 }
1040 }
1041 }
1042 return null;
1043 }
1044
1045 public virtual XmlNode ImportNode(XmlNode node, bool deep)
1046 {
1047 return ImportNodeInternal(node, deep);
1048 }
1049
1051 {
1052 if (node == null)
1053 {
1055 }
1057 switch (node.NodeType)
1058 {
1059 case XmlNodeType.Element:
1060 xmlNode = CreateElement(node.Prefix, node.LocalName, node.NamespaceURI);
1062 if (deep)
1063 {
1065 }
1066 break;
1067 case XmlNodeType.Attribute:
1068 xmlNode = CreateAttribute(node.Prefix, node.LocalName, node.NamespaceURI);
1070 break;
1071 case XmlNodeType.Text:
1072 xmlNode = CreateTextNode(node.Value);
1073 break;
1074 case XmlNodeType.Comment:
1075 xmlNode = CreateComment(node.Value);
1076 break;
1077 case XmlNodeType.ProcessingInstruction:
1079 break;
1080 case XmlNodeType.XmlDeclaration:
1081 {
1084 break;
1085 }
1086 case XmlNodeType.CDATA:
1088 break;
1089 case XmlNodeType.DocumentType:
1090 {
1093 break;
1094 }
1095 case XmlNodeType.DocumentFragment:
1097 if (deep)
1098 {
1100 }
1101 break;
1102 case XmlNodeType.EntityReference:
1104 break;
1105 case XmlNodeType.Whitespace:
1106 xmlNode = CreateWhitespace(node.Value);
1107 break;
1108 case XmlNodeType.SignificantWhitespace:
1110 break;
1111 default:
1113 }
1114 return xmlNode;
1115 }
1116
1118 {
1119 int count = fromElem.Attributes.Count;
1120 for (int i = 0; i < count; i++)
1121 {
1122 if (fromElem.Attributes[i].Specified)
1123 {
1124 toElem.Attributes.SetNamedItem(ImportNodeInternal(fromElem.Attributes[i], deep: true));
1125 }
1126 }
1127 }
1128
1130 {
1131 for (XmlNode xmlNode = fromNode.FirstChild; xmlNode != null; xmlNode = xmlNode.NextSibling)
1132 {
1133 toNode.AppendChild(ImportNodeInternal(xmlNode, deep));
1134 }
1135 }
1136
1137 public virtual XmlAttribute CreateAttribute(string? prefix, string localName, string? namespaceURI)
1138 {
1139 return new XmlAttribute(AddAttrXmlName(prefix, localName, namespaceURI, null), this);
1140 }
1141
1142 protected internal virtual XmlAttribute CreateDefaultAttribute(string? prefix, string localName, string? namespaceURI)
1143 {
1144 return new XmlUnspecifiedAttribute(prefix, localName, namespaceURI, this);
1145 }
1146
1147 public virtual XmlElement CreateElement(string? prefix, string localName, string? namespaceURI)
1148 {
1149 XmlElement xmlElement = new XmlElement(AddXmlName(prefix, localName, namespaceURI, null), empty: true, this);
1150 if (!IsLoading)
1151 {
1153 }
1154 return xmlElement;
1155 }
1156
1157 public virtual XmlNode CreateNode(XmlNodeType type, string? prefix, string name, string? namespaceURI)
1158 {
1159 switch (type)
1160 {
1161 case XmlNodeType.Element:
1162 if (prefix != null)
1163 {
1164 return CreateElement(prefix, name, namespaceURI);
1165 }
1166 return CreateElement(name, namespaceURI);
1167 case XmlNodeType.Attribute:
1168 if (prefix != null)
1169 {
1170 return CreateAttribute(prefix, name, namespaceURI);
1171 }
1172 return CreateAttribute(name, namespaceURI);
1173 case XmlNodeType.Text:
1174 return CreateTextNode(string.Empty);
1175 case XmlNodeType.CDATA:
1176 return CreateCDataSection(string.Empty);
1177 case XmlNodeType.EntityReference:
1178 return CreateEntityReference(name);
1179 case XmlNodeType.ProcessingInstruction:
1180 return CreateProcessingInstruction(name, string.Empty);
1181 case XmlNodeType.XmlDeclaration:
1182 return CreateXmlDeclaration("1.0", null, null);
1183 case XmlNodeType.Comment:
1184 return CreateComment(string.Empty);
1185 case XmlNodeType.DocumentFragment:
1186 return CreateDocumentFragment();
1187 case XmlNodeType.DocumentType:
1188 return CreateDocumentType(name, string.Empty, string.Empty, string.Empty);
1189 case XmlNodeType.Document:
1190 return new XmlDocument();
1191 case XmlNodeType.SignificantWhitespace:
1192 return CreateSignificantWhitespace(string.Empty);
1193 case XmlNodeType.Whitespace:
1194 return CreateWhitespace(string.Empty);
1195 default:
1197 }
1198 }
1199
1200 public virtual XmlNode CreateNode(string nodeTypeString, string name, string? namespaceURI)
1201 {
1203 }
1204
1205 public virtual XmlNode CreateNode(XmlNodeType type, string name, string? namespaceURI)
1206 {
1207 return CreateNode(type, null, name, namespaceURI);
1208 }
1209
1210 public virtual XmlNode? ReadNode(XmlReader reader)
1211 {
1212 XmlNode xmlNode = null;
1213 try
1214 {
1215 IsLoading = true;
1217 return xmlLoader.ReadCurrentNode(this, reader);
1218 }
1219 finally
1220 {
1221 IsLoading = false;
1222 }
1223 }
1224
1226 {
1227 return nodeTypeString switch
1228 {
1229 "element" => XmlNodeType.Element,
1230 "attribute" => XmlNodeType.Attribute,
1231 "text" => XmlNodeType.Text,
1232 "cdatasection" => XmlNodeType.CDATA,
1233 "entityreference" => XmlNodeType.EntityReference,
1234 "entity" => XmlNodeType.Entity,
1235 "processinginstruction" => XmlNodeType.ProcessingInstruction,
1236 "comment" => XmlNodeType.Comment,
1237 "document" => XmlNodeType.Document,
1238 "documenttype" => XmlNodeType.DocumentType,
1239 "documentfragment" => XmlNodeType.DocumentFragment,
1240 "notation" => XmlNodeType.Notation,
1241 "significantwhitespace" => XmlNodeType.SignificantWhitespace,
1242 "whitespace" => XmlNodeType.Whitespace,
1244 };
1245 }
1246
1248 {
1250 tr.EntityHandling = EntityHandling.ExpandCharEntities;
1251 if (HasSetResolver)
1252 {
1254 }
1255 return tr;
1256 }
1257
1258 public virtual void Load(string filename)
1259 {
1261 try
1262 {
1264 }
1265 finally
1266 {
1267 xmlTextReader.Close();
1268 }
1269 }
1270
1271 public virtual void Load(Stream inStream)
1272 {
1274 try
1275 {
1277 }
1278 finally
1279 {
1280 xmlTextReader.Impl.Close(closeInput: false);
1281 }
1282 }
1283
1284 public virtual void Load(TextReader txtReader)
1285 {
1287 try
1288 {
1290 }
1291 finally
1292 {
1293 xmlTextReader.Impl.Close(closeInput: false);
1294 }
1295 }
1296
1297 public virtual void Load(XmlReader reader)
1298 {
1299 try
1300 {
1301 IsLoading = true;
1302 _actualLoadingStatus = true;
1303 RemoveAll();
1304 fEntRefNodesPresent = false;
1305 fCDataNodesPresent = false;
1306 _reportValidity = true;
1308 xmlLoader.Load(this, reader, _preserveWhitespace);
1309 }
1310 finally
1311 {
1312 IsLoading = false;
1313 _actualLoadingStatus = false;
1314 _reportValidity = true;
1315 }
1316 }
1317
1318 public virtual void LoadXml(string xml)
1319 {
1321 try
1322 {
1324 }
1325 finally
1326 {
1327 xmlTextReader.Close();
1328 }
1329 }
1330
1331 public virtual void Save(string filename)
1332 {
1333 if (DocumentElement == null)
1334 {
1336 }
1338 try
1339 {
1341 {
1343 }
1345 xmlDOMTextWriter.Flush();
1346 }
1347 finally
1348 {
1349 xmlDOMTextWriter.Close();
1350 }
1351 }
1352
1353 public virtual void Save(Stream outStream)
1354 {
1357 {
1359 }
1361 xmlDOMTextWriter.Flush();
1362 }
1363
1364 public virtual void Save(TextWriter writer)
1365 {
1368 {
1370 }
1372 }
1373
1374 public virtual void Save(XmlWriter w)
1375 {
1377 if (xmlNode == null)
1378 {
1379 return;
1380 }
1381 if (w.WriteState == WriteState.Start)
1382 {
1384 {
1385 if (Standalone.Length == 0)
1386 {
1387 w.WriteStartDocument();
1388 }
1389 else if (Standalone == "yes")
1390 {
1391 w.WriteStartDocument(standalone: true);
1392 }
1393 else if (Standalone == "no")
1394 {
1395 w.WriteStartDocument(standalone: false);
1396 }
1397 xmlNode = xmlNode.NextSibling;
1398 }
1399 else
1400 {
1401 w.WriteStartDocument();
1402 }
1403 }
1404 while (xmlNode != null)
1405 {
1406 xmlNode.WriteTo(w);
1407 xmlNode = xmlNode.NextSibling;
1408 }
1409 w.Flush();
1410 }
1411
1412 public override void WriteTo(XmlWriter w)
1413 {
1415 }
1416
1417 public override void WriteContentTo(XmlWriter xw)
1418 {
1420 try
1421 {
1422 while (enumerator.MoveNext())
1423 {
1424 XmlNode xmlNode = (XmlNode)enumerator.Current;
1425 xmlNode.WriteTo(xw);
1426 }
1427 }
1428 finally
1429 {
1431 if (disposable != null)
1432 {
1433 disposable.Dispose();
1434 }
1435 }
1436 }
1437
1438 public void Validate(ValidationEventHandler? validationEventHandler)
1439 {
1440 Validate(validationEventHandler, this);
1441 }
1442
1443 public void Validate(ValidationEventHandler? validationEventHandler, XmlNode nodeToValidate)
1444 {
1445 if (_schemas == null || _schemas.Count == 0)
1446 {
1448 }
1450 if (document != this)
1451 {
1453 }
1454 if (nodeToValidate == this)
1455 {
1456 _reportValidity = false;
1457 }
1460 if (nodeToValidate == this)
1461 {
1462 _reportValidity = true;
1463 }
1464 }
1465
1467 {
1468 _reportValidity = false;
1469 switch (action)
1470 {
1471 case XmlNodeChangedAction.Insert:
1473 {
1474 return null;
1475 }
1476 break;
1477 case XmlNodeChangedAction.Remove:
1478 if (_onNodeRemovingDelegate == null && _onNodeRemovedDelegate == null)
1479 {
1480 return null;
1481 }
1482 break;
1483 case XmlNodeChangedAction.Change:
1484 if (_onNodeChangingDelegate == null && _onNodeChangedDelegate == null)
1485 {
1486 return null;
1487 }
1488 break;
1489 }
1491 }
1492
1494 {
1496 {
1497 return null;
1498 }
1499 string value = node.Value;
1501 }
1502
1504 {
1505 if (args == null)
1506 {
1507 return;
1508 }
1509 switch (args.Action)
1510 {
1511 case XmlNodeChangedAction.Insert:
1512 if (_onNodeInsertingDelegate != null)
1513 {
1515 }
1516 break;
1517 case XmlNodeChangedAction.Remove:
1518 if (_onNodeRemovingDelegate != null)
1519 {
1521 }
1522 break;
1523 case XmlNodeChangedAction.Change:
1524 if (_onNodeChangingDelegate != null)
1525 {
1527 }
1528 break;
1529 }
1530 }
1531
1533 {
1534 if (args == null)
1535 {
1536 return;
1537 }
1538 switch (args.Action)
1539 {
1540 case XmlNodeChangedAction.Insert:
1541 if (_onNodeInsertedDelegate != null)
1542 {
1544 }
1545 break;
1546 case XmlNodeChangedAction.Remove:
1547 if (_onNodeRemovedDelegate != null)
1548 {
1550 }
1551 break;
1552 case XmlNodeChangedAction.Change:
1553 if (_onNodeChangedDelegate != null)
1554 {
1556 }
1557 break;
1558 }
1559 }
1560
1562 {
1565 if (schemaElementDecl != null && schemaElementDecl.AttDefs != null)
1566 {
1568 {
1569 SchemaAttDef value = attDef.Value;
1570 if ((value.Presence == SchemaDeclBase.Use.Default || value.Presence == SchemaDeclBase.Use.Fixed) && value.Name.Name == attrLocalname && ((dtdSchemaInfo.SchemaType == SchemaType.DTD && value.Name.Namespace == attrPrefix) || (dtdSchemaInfo.SchemaType != SchemaType.DTD && value.Name.Namespace == attrNamespaceURI)))
1571 {
1573 }
1574 }
1575 }
1576 return null;
1577 }
1578
1579 internal XmlEntity GetEntityNode(string name)
1580 {
1581 if (DocumentType != null)
1582 {
1584 if (entities != null)
1585 {
1586 return (XmlEntity)entities.GetNamedItem(name);
1587 }
1588 }
1589 return null;
1590 }
1591
1592 internal void SetBaseURI(string inBaseURI)
1593 {
1595 }
1596
1630}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
virtual bool Contains(object key)
Definition Hashtable.cs:719
virtual void Remove(object key)
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
static CultureInfo InvariantCulture
static string Arg_CannotCreateNode
Definition SR.cs:1822
static string Xdom_Import_NullNode
Definition SR.cs:1276
static string Xdom_Attr_Reserved_XmlNS
Definition SR.cs:1348
static string Xdom_Node_Insert_TypeConflict
Definition SR.cs:1338
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Xdom_DualDeclarationNode
Definition SR.cs:1272
static string Xdom_Import
Definition SR.cs:1274
static string Xdom_DualDocumentTypeNode
Definition SR.cs:1268
static string Xml_InvalidXmlDocument
Definition SR.cs:216
static string Xdom_Document_Innertext
Definition SR.cs:1314
static string XmlDocument_NodeNotFromDocument
Definition SR.cs:1174
static string Xdom_DualDocumentElementNode
Definition SR.cs:1270
static string Xdom_NoRootEle
Definition SR.cs:1278
static string Xdom_Node_Insert_Location
Definition SR.cs:1336
static string XmlDocument_NoSchemaInfo
Definition SR.cs:1178
static string Xdom_Invalid_NT_String
Definition SR.cs:1308
static string Xml_BadNameChar
Definition SR.cs:44
Definition SR.cs:7
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
XmlName GetName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo)
XmlName AddName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo)
static int ComputeHash32(string key)
Definition NameTable.cs:137
static int ParseNmtoken(string s, int offset)
override? XmlLinkedNode LastNode
static IXmlSchemaInfo NotKnownSchemaInfo
virtual ? XPathNavigator CreateNavigator(XmlNode node)
virtual XmlNode CreateNode(string nodeTypeString, string name, string? namespaceURI)
XmlNodeChangedEventArgs GetInsertEventArgsForLoad(XmlNode node, XmlNode newParent)
override void WriteContentTo(XmlWriter xw)
override string LocalName
virtual XmlDeclaration CreateXmlDeclaration(string version, string? encoding, string? standalone)
void SetDefaultNamespace(string prefix, string localName, ref string namespaceURI)
virtual XmlWhitespace CreateWhitespace(string? text)
XmlAttribute _namespaceXml
XmlImplementation Implementation
void Validate(ValidationEventHandler? validationEventHandler, XmlNode nodeToValidate)
virtual XmlNode ImportNode(XmlNode node, bool deep)
XmlNodeChangedEventHandler NodeChanged
XmlNodeChangedEventHandler _onNodeInsertingDelegate
override XmlNodeChangedEventArgs GetEventArgs(XmlNode node, XmlNode oldParent, XmlNode newParent, string oldValue, string newValue, XmlNodeChangedAction action)
XmlNodeChangedEventHandler _onNodeChangingDelegate
void AddElementWithId(string id, XmlElement elem)
override bool CanInsertBefore(XmlNode newChild, XmlNode refChild)
virtual void Load(string filename)
virtual XmlText CreateTextNode(string? text)
Hashtable _htElementIDAttrDecl
override string InnerXml
override? XmlDocument OwnerDocument
static bool IsTextNode(XmlNodeType nt)
XmlAttribute GetDefaultAttribute(XmlElement elem, string attrPrefix, string attrLocalname, string attrNamespaceURI)
XmlAttribute CreateAttribute(string qualifiedName, string? namespaceURI)
virtual void Load(Stream inStream)
override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
override bool IsContainer
virtual XmlAttribute CreateDefaultAttribute(string? prefix, string localName, string? namespaceURI)
XmlNodeChangedEventHandler NodeInserting
XmlNode NormalizeText(XmlNode node)
virtual XmlDocumentFragment CreateDocumentFragment()
virtual XmlAttribute CreateAttribute(string? prefix, string localName, string? namespaceURI)
XmlDocument(XmlImplementation imp)
static IXmlSchemaInfo InvalidSchemaInfo
static readonly(string key, int hash)[] s_nameTableSeeds
virtual XmlNodeList GetElementsByTagName(string localName, string namespaceURI)
XmlSchemaSet _schemas
XmlResolver GetResolver()
virtual XmlNode CreateNode(XmlNodeType type, string? prefix, string name, string? namespaceURI)
override XmlNodeType NodeType
WeakReference< XmlElement > GetElement(ArrayList elementList, XmlElement elem)
override? XPathNavigator CreateNavigator()
XmlNode ImportNodeInternal(XmlNode node, bool deep)
XmlNodeChangedEventHandler NodeInserted
virtual ? XmlDocumentType DocumentType
readonly DomNameTable _domNameTable
override XPathNodeType XPNodeType
override string Name
XmlAttribute NamespaceXml
virtual ? XmlNode ReadNode(XmlReader reader)
virtual void Save(string filename)
bool AddIdInfo(XmlName eleName, XmlName attrName)
readonly XmlImplementation _implementation
static EmptyEnumerator EmptyEnumerator
virtual XmlCDataSection CreateCDataSection(string? data)
override bool IsReadOnly
virtual ? XmlDeclaration Declaration
XmlName GetXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
virtual XmlProcessingInstruction CreateProcessingInstruction(string target, string data)
override string InnerText
XmlNodeChangedEventHandler NodeChanging
virtual void Save(TextWriter writer)
virtual XmlNodeList GetElementsByTagName(string name)
XmlName AddXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
virtual void Load(TextReader txtReader)
XmlNodeChangedEventHandler _onNodeRemovingDelegate
void SetBaseURI(string inBaseURI)
string strSignificantWhitespaceName
override string BaseURI
virtual XmlSignificantWhitespace CreateSignificantWhitespace(string? text)
string strNonSignificantWhitespaceName
virtual XmlEntityReference CreateEntityReference(string name)
XmlName GetIDInfoByElement(XmlName eleName)
virtual void Save(Stream outStream)
override void BeforeEvent(XmlNodeChangedEventArgs args)
XmlDocument(XmlNameTable nt)
XmlElement CreateElement(string qualifiedName, string? namespaceURI)
virtual void Load(XmlReader reader)
virtual XmlElement CreateElement(string? prefix, string localName, string? namespaceURI)
void RemoveElementWithId(string id, XmlElement elem)
XmlNodeChangedEventHandler NodeRemoving
SchemaInfo? DtdSchemaInfo
XmlNodeType ConvertToNodeType(string nodeTypeString)
XmlNodeChangedEventHandler _onNodeInsertedDelegate
override bool IsValidChildType(XmlNodeType type)
static void CheckName(string name)
override? XmlNode ParentNode
XmlNodeChangedEventHandler _onNodeRemovedDelegate
XmlAttribute PrepareDefaultAttribute(SchemaAttDef attdef, string attrPrefix, string attrLocalname, string attrNamespaceURI)
virtual void Save(XmlWriter w)
XmlElement CreateElement(string name)
override bool CanInsertAfter(XmlNode newChild, XmlNode refChild)
override void AfterEvent(XmlNodeChangedEventArgs args)
override XmlNode CloneNode(bool deep)
static IXmlSchemaInfo ValidSchemaInfo
XmlLinkedNode _lastChild
virtual XmlNode CreateNode(XmlNodeType type, string name, string? namespaceURI)
void ImportChildren(XmlNode fromNode, XmlNode toNode, bool deep)
XmlElement? DocumentElement
virtual XmlComment CreateComment(string? data)
bool HasNodeTypeInPrevSiblings(XmlNodeType nt, XmlNode refNode)
XmlEntity GetEntityNode(string name)
XmlNodeChangedEventHandler _onNodeChangedDelegate
virtual XmlDocumentType CreateDocumentType(string name, string? publicId, string? systemId, string? internalSubset)
XmlNodeChangedEventHandler NodeRemoved
SchemaElementDecl GetSchemaElementDecl(XmlElement elem)
XmlName AddAttrXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
virtual ? XmlElement GetElementById(string elementId)
bool HasNodeTypeInNextSiblings(XmlNodeType nt, XmlNode refNode)
virtual void LoadXml(string xml)
override void WriteTo(XmlWriter w)
void AddDefaultAttributes(XmlElement elem)
XmlNamedNodeMap Entities
XmlTextReader SetupReader(XmlTextReader tr)
XmlNamedNodeMap _entities
XmlAttribute CreateAttribute(string name)
void ImportAttributes(XmlNode fromElem, XmlNode toElem)
XmlName GetIDInfoByElement_(XmlName eleName)
void Validate(ValidationEventHandler? validationEventHandler)
static string[] BuildCharExceptionArgs(string data, int invCharIndex)
virtual XmlDocument CreateDocument()
virtual XmlNode FindChild(XmlNodeType type)
Definition XmlNode.cs:1227
virtual ? XmlNode LastChild
Definition XmlNode.cs:122
virtual ? XmlNode FirstChild
Definition XmlNode.cs:120
static void SplitName(string name, out string prefix, out string localName)
Definition XmlNode.cs:1212
virtual void RemoveAll()
Definition XmlNode.cs:1033
IEnumerator IEnumerable. GetEnumerator()
Definition XmlNode.cs:1001
virtual bool HasChildNodes
Definition XmlNode.cs:137
delegate void XmlNodeChangedEventHandler(object sender, XmlNodeChangedEventArgs e)