Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlSchemaValidator.cs
Go to the documentation of this file.
4using System.IO;
5using System.Text;
7
8namespace System.Xml.Schema;
9
10public sealed class XmlSchemaValidator
11{
12 private readonly XmlSchemaSet _schemaSet;
13
15
16 private int _startIDConstraint = -1;
17
18 private bool _isRoot;
19
20 private bool _rootHasSchema;
21
22 private bool _attrValid;
23
24 private bool _checkEntity;
25
27
29
31
33
35
37
39
41
42 private Hashtable _IDs;
43
45
47
48 private string _nsXs;
49
50 private string _nsXsi;
51
52 private string _nsXmlNs;
53
54 private string _nsXml;
55
57
59
60 private ValidationEventHandler _eventHandler;
61
62 private object _validationEventSender;
63
64 private readonly XmlNameTable _nameTable;
65
67
68 private static readonly IXmlLineInfo s_dummyPositionInfo = new PositionInfo();
69
71
72 private Uri _sourceUri;
73
74 private string _sourceUriString;
75
77
79
81
83
85
87
88 private string _xsiTypeString;
89
90 private string _xsiNilString;
91
93
95
97
99
100 private static readonly XmlSchemaDatatype s_dtStringArray = s_dtCDATA.DeriveByList(null);
101
102 internal static bool[,] ValidStates = new bool[12, 12]
103 {
104 {
105 true, true, false, false, false, false, false, false, false, false,
106 false, false
107 },
108 {
109 false, true, true, true, true, false, false, false, false, false,
110 false, true
111 },
112 {
113 false, false, false, false, false, false, false, false, false, false,
114 false, true
115 },
116 {
117 false, false, false, true, true, false, false, false, false, false,
118 false, true
119 },
120 {
121 false, false, false, true, false, true, true, false, false, true,
122 true, false
123 },
124 {
125 false, false, false, false, false, true, true, false, false, true,
126 true, false
127 },
128 {
129 false, false, false, false, true, false, false, true, true, true,
130 true, false
131 },
132 {
133 false, false, false, false, true, false, false, true, true, true,
134 true, false
135 },
136 {
137 false, false, false, false, true, false, false, true, true, true,
138 true, false
139 },
140 {
141 false, false, false, true, true, false, false, true, true, true,
142 true, true
143 },
144 {
145 false, false, false, true, true, false, false, true, true, true,
146 true, true
147 },
148 {
149 false, true, false, false, false, false, false, false, false, false,
150 false, false
151 }
152 };
153
154 private static readonly string[] s_methodNames = new string[12]
155 {
156 "None", "Initialize", "top-level ValidateAttribute", "top-level ValidateText or ValidateWhitespace", "ValidateElement", "ValidateAttribute", "ValidateEndOfAttributes", "ValidateText", "ValidateWhitespace", "ValidateEndElement",
157 "SkipToEndElement", "EndValidation"
158 };
159
161 {
162 set
163 {
165 }
166 }
167
169 {
170 get
171 {
172 return _positionInfo;
173 }
175 set
176 {
177 if (value == null)
178 {
180 }
181 else
182 {
184 }
185 }
186 }
187
189 {
190 get
191 {
192 return _sourceUri;
193 }
195 set
196 {
199 }
200 }
201
203 {
204 get
205 {
207 }
208 set
209 {
211 }
212 }
213
215
217
219 {
220 get
221 {
222 if (_context.ElementDecl == null)
223 {
224 return XmlSchemaContentType.Empty;
225 }
227 }
228 }
229
231
232 private bool StrictlyAssessed
233 {
234 get
235 {
237 {
239 }
240 return false;
241 }
242 }
243
244 private bool HasSchema
245 {
246 get
247 {
248 if (_isRoot)
249 {
250 _isRoot = false;
252 {
253 _rootHasSchema = false;
254 }
255 }
256 return _rootHasSchema;
257 }
258 }
259
261 {
262 get
263 {
265 {
266 return _startIDConstraint != -1;
267 }
268 return false;
269 }
270 }
271
272 internal bool ProcessIdentityConstraints => (_validationFlags & XmlSchemaValidationFlags.ProcessIdentityConstraints) != 0;
273
274 internal bool ReportValidationWarnings => (_validationFlags & XmlSchemaValidationFlags.ReportValidationWarnings) != 0;
275
276 internal bool ProcessSchemaHints
277 {
278 get
279 {
280 if ((_validationFlags & XmlSchemaValidationFlags.ProcessInlineSchema) == 0)
281 {
282 return (_validationFlags & XmlSchemaValidationFlags.ProcessSchemaLocation) != 0;
283 }
284 return true;
285 }
286 }
287
288 public event ValidationEventHandler? ValidationEventHandler
289 {
290 add
291 {
293 }
294 remove
295 {
297 }
298 }
299
301 {
302 if (nameTable == null)
303 {
304 throw new ArgumentNullException("nameTable");
305 }
306 if (schemas == null)
307 {
308 throw new ArgumentNullException("schemas");
309 }
310 if (namespaceResolver == null)
311 {
312 throw new ArgumentNullException("namespaceResolver");
313 }
317 if ((validationFlags & XmlSchemaValidationFlags.ProcessInlineSchema) != 0 || (validationFlags & XmlSchemaValidationFlags.ProcessSchemaLocation) != 0)
318 {
323 _schemaSet.Add(schemas);
325 }
326 else
327 {
328 _schemaSet = schemas;
329 }
330 Init();
331 }
332
333 [MemberNotNull("_validationStack")]
334 [MemberNotNull("_attPresence")]
335 [MemberNotNull("_positionInfo")]
336 [MemberNotNull("_validationEventSender")]
337 [MemberNotNull("_currentState")]
338 [MemberNotNull("_textValue")]
339 [MemberNotNull("_context")]
340 [MemberNotNull("_contextQName")]
341 [MemberNotNull("_nsXs")]
342 [MemberNotNull("_nsXsi")]
343 [MemberNotNull("_nsXmlNs")]
344 [MemberNotNull("_nsXml")]
345 [MemberNotNull("_xsiTypeString")]
346 [MemberNotNull("_xsiNilString")]
347 [MemberNotNull("_xsiSchemaLocationString")]
348 [MemberNotNull("_xsiNoNamespaceSchemaLocationString")]
349 [MemberNotNull("_compiledSchemaInfo")]
350 private void Init()
351 {
352 _validationStack = new HWStack(10);
353 _attPresence = new Hashtable();
358 _textValue = new StringBuilder(100);
359 _xmlResolver = null;
361 Reset();
363 _nsXs = _nameTable.Add("http://www.w3.org/2001/XMLSchema");
364 _nsXsi = _nameTable.Add("http://www.w3.org/2001/XMLSchema-instance");
365 _nsXmlNs = _nameTable.Add("http://www.w3.org/2000/xmlns/");
366 _nsXml = _nameTable.Add("http://www.w3.org/XML/1998/namespace");
367 _xsiTypeString = _nameTable.Add("type");
369 _xsiSchemaLocationString = _nameTable.Add("schemaLocation");
370 _xsiNoNamespaceSchemaLocationString = _nameTable.Add("noNamespaceSchemaLocation");
371 }
372
373 private void Reset()
374 {
375 _isRoot = true;
376 _rootHasSchema = true;
377 while (_validationStack.Length > 1)
378 {
380 }
383 if (_IDs != null)
384 {
385 _IDs.Clear();
386 }
388 {
390 }
391 }
392
394 {
395 if (schema == null)
396 {
397 throw new ArgumentNullException("schema");
398 }
399 if ((_validationFlags & XmlSchemaValidationFlags.ProcessInlineSchema) == 0)
400 {
401 return;
402 }
403 string text = schema.TargetNamespace;
404 if (text == null)
405 {
406 text = string.Empty;
407 }
411 if (_validatedNamespaces[text] != null && _schemaSet.FindSchemaByNSAndUrl(schema.BaseUri, text, array) == null)
412 {
414 }
415 if (schema.ErrorCount != 0)
416 {
417 return;
418 }
419 try
420 {
423 }
424 catch (XmlSchemaException ex)
425 {
427 {
428 schema.BaseUri.ToString(),
429 ex.Message
430 }, ex);
431 }
432 for (int i = 0; i < schema.ImportedSchemas.Count; i++)
433 {
434 XmlSchema xmlSchema = (XmlSchema)schema.ImportedSchemas[i];
435 text = xmlSchema.TargetNamespace;
436 if (text == null)
437 {
438 text = string.Empty;
439 }
441 {
444 break;
445 }
446 }
447 }
448
449 public void Initialize()
450 {
451 if (_currentState != 0 && _currentState != ValidatorState.Finish)
452 {
454 object[] args = new string[2]
455 {
458 };
460 }
462 Reset();
463 }
464
489
490 public void ValidateElement(string localName, string namespaceUri, XmlSchemaInfo? schemaInfo)
491 {
492 ValidateElement(localName, namespaceUri, schemaInfo, null, null, null, null);
493 }
494
495 public void ValidateElement(string localName, string namespaceUri, XmlSchemaInfo? schemaInfo, string? xsiType, string? xsiNil, string? xsiSchemaLocation, string? xsiNoNamespaceSchemaLocation)
496 {
497 if (localName == null)
498 {
499 throw new ArgumentNullException("localName");
500 }
501 if (namespaceUri == null)
502 {
503 throw new ArgumentNullException("namespaceUri");
504 }
506 ClearPSVI();
507 _contextQName.Init(localName, namespaceUri);
514 {
516 }
517 if ((_validationFlags & XmlSchemaValidationFlags.ProcessSchemaLocation) != 0 && _xmlResolver != null)
518 {
520 }
522 {
523 if (schemaElementDecl == null && _partialValidationType == null)
524 {
526 }
527 bool declFound = schemaElementDecl != null;
528 if (xsiType != null || xsiNil != null)
529 {
531 }
532 if (schemaElementDecl == null)
533 {
535 }
536 }
539 XmlSchemaType schemaType = null;
540 if (schemaElementDecl != null)
541 {
546 schemaElementDecl.ContentValidator.InitValidation(_context);
547 schemaType = schemaElementDecl.SchemaType;
549 }
550 if (schemaInfo != null)
551 {
552 schemaInfo.SchemaType = schemaType;
556 }
557 if (ProcessSchemaHints && _validatedNamespaces[namespaceUri] == null)
558 {
559 _validatedNamespaces.Add(namespaceUri, namespaceUri);
560 }
561 if (_isRoot)
562 {
563 _isRoot = false;
564 }
565 }
566
567 public object? ValidateAttribute(string localName, string namespaceUri, string attributeValue, XmlSchemaInfo? schemaInfo)
568 {
569 if (attributeValue == null)
570 {
571 throw new ArgumentNullException("attributeValue");
572 }
573 return ValidateAttribute(localName, namespaceUri, null, attributeValue, schemaInfo);
574 }
575
576 public object? ValidateAttribute(string localName, string namespaceUri, XmlValueGetter attributeValue, XmlSchemaInfo? schemaInfo)
577 {
578 if (attributeValue == null)
579 {
580 throw new ArgumentNullException("attributeValue");
581 }
582 return ValidateAttribute(localName, namespaceUri, attributeValue, null, schemaInfo);
583 }
584
585 private object ValidateAttribute(string localName, string namespaceUri, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo)
586 {
587 if (localName == null)
588 {
589 throw new ArgumentNullException("localName");
590 }
591 if (namespaceUri == null)
592 {
593 throw new ArgumentNullException("namespaceUri");
594 }
597 object obj = null;
598 _attrValid = true;
602 namespaceUri = _nameTable.Add(namespaceUri);
603 if (Ref.Equal(namespaceUri, _nsXmlNs))
604 {
605 return null;
606 }
609 XmlQualifiedName xmlQualifiedName = new XmlQualifiedName(localName, namespaceUri);
610 if (_attPresence[xmlQualifiedName] != null)
611 {
613 schemaInfo?.Clear();
614 return null;
615 }
616 if (!Ref.Equal(namespaceUri, _nsXsi))
617 {
620 switch (attributeMatchState)
621 {
622 case AttributeMatchState.UndeclaredElementAndAttribute:
624 {
625 if (elementDecl == null && _processContents == XmlSchemaContentProcessing.Strict && xmlQualifiedName.Namespace.Length != 0 && _compiledSchemaInfo.Contains(xmlQualifiedName.Namespace))
626 {
627 _attrValid = false;
629 }
631 {
633 }
634 break;
635 }
636 goto case AttributeMatchState.AttributeFound;
637 case AttributeMatchState.UndeclaredAttribute:
639 {
640 _attrValid = false;
642 break;
643 }
644 goto case AttributeMatchState.AttributeFound;
645 case AttributeMatchState.ProhibitedAnyAttribute:
647 {
648 _attrValid = false;
650 break;
651 }
652 goto case AttributeMatchState.AttributeFound;
653 case AttributeMatchState.ProhibitedAttribute:
654 _attrValid = false;
656 break;
657 case AttributeMatchState.AttributeNameMismatch:
658 _attrValid = false;
660 {
661 xmlQualifiedName.ToString(),
662 ((XmlSchemaAttribute)xmlSchemaObject).QualifiedName.ToString()
663 });
664 break;
665 case AttributeMatchState.ValidateAttributeInvalidCall:
667 _attrValid = false;
669 break;
670 case AttributeMatchState.AnyIdAttributeFound:
671 if (_wildID == null)
672 {
675 if (xmlSchemaComplexType.ContainsIdAttribute(findAll: false))
676 {
678 break;
679 }
680 goto case AttributeMatchState.AttributeFound;
681 }
683 break;
684 case AttributeMatchState.AttributeFound:
685 {
686 xmlSchemaAttribute = schemaAttDef.SchemaAttribute;
687 if (elementDecl != null)
688 {
690 }
693 XmlSchemaDatatype datatype = schemaAttDef.Datatype;
694 if (datatype.Variety == XmlSchemaDatatypeVariety.Union && obj != null)
695 {
697 memberType = xsdSimpleValue.XmlType;
698 datatype = xsdSimpleValue.XmlType.Datatype;
699 obj = xsdSimpleValue.TypedValue;
700 }
701 CheckTokenizedTypes(datatype, obj, attrValue: true);
703 {
704 AttributeIdentityConstraints(xmlQualifiedName.Name, xmlQualifiedName.Namespace, obj, obj2.ToString(), datatype);
705 }
706 break;
707 }
708 case AttributeMatchState.AnyAttributeLax:
710 break;
711 }
712 }
713 else
714 {
715 localName = _nameTable.Add(localName);
717 {
719 }
720 else
721 {
722 _attrValid = false;
724 }
725 }
726 if (!_attrValid)
727 {
728 validity = XmlSchemaValidity.Invalid;
729 }
730 else if (schemaAttDef != null)
731 {
733 }
734 if (schemaInfo != null)
735 {
737 schemaInfo.SchemaType = xmlSchemaAttribute?.AttributeSchemaType;
739 schemaInfo.IsDefault = false;
741 }
742 if (ProcessSchemaHints && _validatedNamespaces[namespaceUri] == null)
743 {
744 _validatedNamespaces.Add(namespaceUri, namespaceUri);
745 }
746 return obj;
747 }
748
749 public void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes)
750 {
751 if (defaultAttributes == null)
752 {
753 throw new ArgumentNullException("defaultAttributes");
754 }
755 CheckStateTransition(ValidatorState.Attribute, "GetUnspecifiedDefaultAttributes");
756 GetUnspecifiedDefaultAttributes(defaultAttributes, createNodeData: false);
757 }
758
759 public void ValidateEndOfAttributes(XmlSchemaInfo? schemaInfo)
760 {
763 if (elementDecl != null && elementDecl.HasRequiredAttribute)
764 {
767 }
768 if (schemaInfo != null)
769 {
771 }
772 }
773
774 public void ValidateText(string elementValue)
775 {
776 if (elementValue == null)
777 {
778 throw new ArgumentNullException("elementValue");
779 }
781 }
782
783 public void ValidateText(XmlValueGetter elementValue)
784 {
785 if (elementValue == null)
786 {
787 throw new ArgumentNullException("elementValue");
788 }
790 }
791
792 private void ValidateText(string elementStringValue, XmlValueGetter elementValueGetter)
793 {
797 {
798 return;
799 }
800 if (_context.IsNill)
801 {
803 return;
804 }
806 {
807 case XmlSchemaContentType.Empty:
809 break;
810 case XmlSchemaContentType.TextOnly:
811 if (elementValueGetter != null)
812 {
814 }
815 else
816 {
818 }
819 break;
820 case XmlSchemaContentType.ElementOnly:
821 {
822 string str = ((elementValueGetter != null) ? elementValueGetter().ToString() : elementStringValue);
824 {
826 if (arrayList == null || arrayList.Count == 0)
827 {
829 break;
830 }
832 {
833 BuildElementName(_context.LocalName, _context.Namespace),
834 PrintExpectedElements(arrayList, getParticles: true)
835 });
836 }
837 break;
838 }
839 case XmlSchemaContentType.Mixed:
841 {
842 if (elementValueGetter != null)
843 {
845 }
846 else
847 {
849 }
850 }
851 break;
852 }
853 }
854
856 {
857 if (elementValue == null)
858 {
859 throw new ArgumentNullException("elementValue");
860 }
862 }
863
864 public void ValidateWhitespace(XmlValueGetter elementValue)
865 {
866 if (elementValue == null)
867 {
868 throw new ArgumentNullException("elementValue");
869 }
871 }
872
873 private void ValidateWhitespace(string elementStringValue, XmlValueGetter elementValueGetter)
874 {
878 {
879 return;
880 }
881 if (_context.IsNill)
882 {
884 }
886 {
887 case XmlSchemaContentType.Empty:
889 break;
890 case XmlSchemaContentType.TextOnly:
891 if (elementValueGetter != null)
892 {
894 }
895 else
896 {
898 }
899 break;
900 case XmlSchemaContentType.Mixed:
902 {
903 if (elementValueGetter != null)
904 {
906 }
907 else
908 {
910 }
911 }
912 break;
913 case XmlSchemaContentType.ElementOnly:
914 break;
915 }
916 }
917
918 public object? ValidateEndElement(XmlSchemaInfo? schemaInfo)
919 {
920 return InternalValidateEndElement(schemaInfo, null);
921 }
922
923 public object? ValidateEndElement(XmlSchemaInfo? schemaInfo, object typedValue)
924 {
925 if (typedValue == null)
926 {
927 throw new ArgumentNullException("typedValue");
928 }
929 if (_textValue.Length > 0)
930 {
932 }
933 return InternalValidateEndElement(schemaInfo, typedValue);
934 }
935
936 public void SkipToEndElement(XmlSchemaInfo? schemaInfo)
937 {
938 if (_validationStack.Length <= 1)
939 {
941 }
943 if (schemaInfo != null)
944 {
946 if (elementDecl != null)
947 {
950 }
951 else
952 {
955 }
960 }
962 _currentState = ValidatorState.SkipToEndElement;
963 Pop();
964 }
965
975
977 {
978 if (_currentState == ValidatorState.Start || _currentState == ValidatorState.TopLevelTextOrWS)
979 {
980 if (_partialValidationType != null)
981 {
983 {
984 return new XmlSchemaParticle[1] { xmlSchemaElement };
985 }
986 return Array.Empty<XmlSchemaParticle>();
987 }
989 ArrayList arrayList = new ArrayList(values.Count);
990 foreach (XmlSchemaElement item in values)
991 {
993 }
995 }
996 if (_context.ElementDecl != null)
997 {
999 if (arrayList2 != null)
1000 {
1002 }
1003 }
1004 return Array.Empty<XmlSchemaParticle>();
1005 }
1006
1008 {
1009 if (_currentState == ValidatorState.Element || _currentState == ValidatorState.Attribute)
1010 {
1013 if (elementDecl != null)
1014 {
1015 foreach (SchemaAttDef value in elementDecl.AttDefs.Values)
1016 {
1017 if (_attPresence[value.Name] == null)
1018 {
1019 arrayList.Add(value.SchemaAttribute);
1020 }
1021 }
1022 }
1023 if (_nsResolver.LookupPrefix(_nsXsi) != null)
1024 {
1026 }
1028 }
1030 {
1031 return new XmlSchemaAttribute[1] { xmlSchemaAttribute };
1032 }
1033 return Array.Empty<XmlSchemaAttribute>();
1034 }
1035
1036 internal void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes, bool createNodeData)
1037 {
1038 _currentState = ValidatorState.Attribute;
1040 if (elementDecl == null || !elementDecl.HasDefaultAttribute)
1041 {
1042 return;
1043 }
1044 for (int i = 0; i < elementDecl.DefaultAttDefs.Count; i++)
1045 {
1047 if (_attPresence.Contains(schemaAttDef.Name) || schemaAttDef.DefaultValueTyped == null)
1048 {
1049 continue;
1050 }
1051 string text = _nameTable.Add(schemaAttDef.Name.Namespace);
1052 string text2 = string.Empty;
1053 if (text.Length > 0)
1054 {
1056 if (text2 == null || text2.Length == 0)
1057 {
1059 {
1060 schemaAttDef.Name.ToString(),
1061 QNameString(_context.LocalName, _context.Namespace)
1062 });
1063 continue;
1064 }
1065 }
1066 XmlSchemaDatatype datatype = schemaAttDef.Datatype;
1067 if (createNodeData)
1068 {
1075 XmlSchemaInfo attributeSchemaInfo = attributePSVIInfo.attributeSchemaInfo;
1076 if (schemaAttDef.Datatype.Variety == XmlSchemaDatatypeVariety.Union)
1077 {
1080 datatype = xsdSimpleValue.XmlType.Datatype;
1082 }
1083 else
1084 {
1086 }
1091 validatingReaderNodeData.RawValue = attributeSchemaInfo.XmlType.ValueConverter.ToString(attributePSVIInfo.typedAttributeValue);
1093 defaultAttributes.Add(validatingReaderNodeData);
1094 }
1095 else
1096 {
1097 defaultAttributes.Add(schemaAttDef.SchemaAttribute);
1098 }
1099 CheckTokenizedTypes(datatype, schemaAttDef.DefaultValueTyped, attrValue: true);
1101 {
1102 AttributeIdentityConstraints(schemaAttDef.Name.Name, schemaAttDef.Name.Namespace, schemaAttDef.DefaultValueTyped, schemaAttDef.DefaultValueRaw, datatype);
1103 }
1104 }
1105 }
1106
1108 {
1110 _checkEntity = true;
1111 }
1112
1113 internal string GetConcatenatedValue()
1114 {
1115 return _textValue.ToString();
1116 }
1117
1118 private object InternalValidateEndElement(XmlSchemaInfo schemaInfo, object typedValue)
1119 {
1120 if (_validationStack.Length <= 1)
1121 {
1123 }
1127 XmlSchemaType schemaType = null;
1129 string text = string.Empty;
1130 if (elementDecl != null)
1131 {
1132 if (_context.CheckRequiredAttribute && elementDecl.HasRequiredAttribute)
1133 {
1135 }
1137 {
1138 switch (elementDecl.ContentValidator.ContentType)
1139 {
1140 case XmlSchemaContentType.TextOnly:
1141 if (typedValue == null)
1142 {
1144 typedValue = ValidateAtomicValue(text, out memberType);
1145 }
1146 else
1147 {
1148 typedValue = ValidateAtomicValue(typedValue, out memberType);
1149 }
1150 break;
1151 case XmlSchemaContentType.Mixed:
1152 if (elementDecl.DefaultValueTyped != null && typedValue == null)
1153 {
1155 typedValue = CheckMixedValueConstraint(text);
1156 }
1157 break;
1158 case XmlSchemaContentType.ElementOnly:
1159 if (typedValue != null)
1160 {
1162 }
1163 break;
1164 }
1165 if (!elementDecl.ContentValidator.CompleteValidation(_context))
1166 {
1169 }
1170 }
1172 {
1173 XmlSchemaType xmlSchemaType = ((memberType == null) ? elementDecl.SchemaType : memberType);
1174 EndElementIdentityConstraints(typedValue, text, xmlSchemaType.Datatype);
1175 }
1176 schemaType = elementDecl.SchemaType;
1178 }
1179 if (schemaInfo != null)
1180 {
1181 schemaInfo.SchemaType = schemaType;
1187 {
1189 }
1191 }
1192 Pop();
1193 return typedValue;
1194 }
1195
1197 {
1198 bool flag = false;
1199 if (xsiNoNamespaceSchemaLocation != null)
1200 {
1201 flag = true;
1203 }
1204 if (xsiSchemaLocation != null)
1205 {
1206 object typedValue;
1208 if (ex != null)
1209 {
1210 SendValidationEvent(System.SR.Sch_InvalidValueDetailedAttribute, new string[4] { "schemaLocation", xsiSchemaLocation, s_dtStringArray.TypeCodeString, ex.Message }, ex);
1211 return;
1212 }
1213 string[] array = (string[])typedValue;
1214 flag = true;
1215 try
1216 {
1217 for (int i = 0; i < array.Length - 1; i += 2)
1218 {
1219 LoadSchema(array[i], array[i + 1]);
1220 }
1221 }
1222 catch (XmlSchemaException e)
1223 {
1225 }
1226 }
1227 if (flag)
1228 {
1230 }
1231 }
1232
1234 {
1235 object obj = null;
1236 int errorCode = 0;
1240 {
1241 if (_context.IsNill)
1242 {
1244 return null;
1245 }
1248 {
1250 return null;
1251 }
1252 XmlQualifiedName xmlQualifiedName = elementName;
1253 bool flag = false;
1254 while (true)
1255 {
1257 if (obj != null)
1258 {
1259 break;
1260 }
1261 if (errorCode == -2)
1262 {
1266 return null;
1267 }
1268 flag = true;
1270 if (xmlSchemaElement == null)
1271 {
1272 break;
1273 }
1274 xmlQualifiedName = xmlSchemaElement.QualifiedName;
1275 }
1276 if (flag)
1277 {
1279 {
1280 obj = null;
1281 }
1282 else if (xmlSchemaElement2.RefName.IsEmpty)
1283 {
1287 }
1288 else
1289 {
1290 obj = _compiledSchemaInfo.GetElement(elementName);
1292 }
1293 }
1294 if (obj == null)
1295 {
1299 }
1300 }
1301 return obj;
1302 }
1303
1305 {
1307 if (element != null)
1308 {
1310 if (!substitutionGroup.IsEmpty)
1311 {
1313 if (element2 != null)
1314 {
1315 if ((element2.BlockResolved & XmlSchemaDerivationMethod.Substitution) != 0)
1316 {
1318 {
1319 member.ToString(),
1320 substitutionGroup.ToString()
1321 });
1322 return null;
1323 }
1324 if (!XmlSchemaType.IsDerivedFrom(element.ElementSchemaType, element2.ElementSchemaType, element2.BlockResolved))
1325 {
1327 {
1328 member.ToString(),
1329 substitutionGroup.ToString()
1330 });
1331 return null;
1332 }
1333 return element2;
1334 }
1335 }
1336 }
1337 return null;
1338 }
1339
1341 {
1342 object typedValue = null;
1343 memberType = null;
1344 if (!_context.IsNill)
1345 {
1347 if (stringValue.Length == 0 && elementDecl.DefaultValueTyped != null)
1348 {
1351 {
1352 Exception ex = elementDecl.Datatype.TryParseValue(elementDecl.DefaultValueRaw, _nameTable, _nsResolver, out typedValue);
1353 if (ex != null)
1354 {
1356 {
1357 elementDecl.DefaultValueRaw,
1358 QNameString(_context.LocalName, _context.Namespace)
1359 });
1360 }
1361 else
1362 {
1363 _context.IsDefault = true;
1364 }
1365 }
1366 else
1367 {
1368 _context.IsDefault = true;
1369 typedValue = elementDecl.DefaultValueTyped;
1370 }
1371 }
1372 else
1373 {
1374 typedValue = CheckElementValue(stringValue);
1375 }
1377 XmlSchemaDatatype datatype = elementDecl.Datatype;
1378 if (xsdSimpleValue != null)
1379 {
1380 memberType = xsdSimpleValue.XmlType;
1381 typedValue = xsdSimpleValue.TypedValue;
1382 datatype = memberType.Datatype;
1383 }
1384 CheckTokenizedTypes(datatype, typedValue, attrValue: false);
1385 }
1386 return typedValue;
1387 }
1388
1390 {
1391 object typedValue = null;
1392 memberType = null;
1393 if (!_context.IsNill)
1394 {
1397 XmlSchemaDatatype datatype = elementDecl.Datatype;
1399 if (ex != null)
1400 {
1401 string text = parsedValue as string;
1402 if (text == null)
1403 {
1405 }
1407 {
1408 QNameString(_context.LocalName, _context.Namespace),
1409 text,
1410 GetTypeName(schemaDeclBase),
1411 ex.Message
1412 }, ex);
1413 return null;
1414 }
1415 if (!schemaDeclBase.CheckValue(typedValue))
1416 {
1418 }
1419 if (datatype.Variety == XmlSchemaDatatypeVariety.Union)
1420 {
1422 memberType = xsdSimpleValue.XmlType;
1423 typedValue = xsdSimpleValue.TypedValue;
1424 datatype = memberType.Datatype;
1425 }
1426 CheckTokenizedTypes(datatype, typedValue, attrValue: false);
1427 }
1428 return typedValue;
1429 }
1430
1432 {
1433 string text = decl.SchemaType.QualifiedName.ToString();
1434 if (text.Length == 0)
1435 {
1436 text = decl.Datatype.TypeCodeString;
1437 }
1438 return text;
1439 }
1440
1441 private void SaveTextValue(object value)
1442 {
1443 string value2 = value.ToString();
1445 }
1446
1447 [MemberNotNull("_context")]
1448 private void Push(XmlQualifiedName elementName)
1449 {
1451 if (_context == null)
1452 {
1453 _context = new ValidationState();
1455 }
1456 _context.LocalName = elementName.Name;
1457 _context.Namespace = elementName.Namespace;
1458 _context.HasMatched = false;
1459 _context.IsNill = false;
1460 _context.IsDefault = false;
1467 _context.Constr = null;
1468 }
1469
1470 private void Pop()
1471 {
1474 {
1475 _startIDConstraint = -1;
1476 }
1478 if (validationState.Validity == XmlSchemaValidity.Invalid)
1479 {
1481 }
1482 if (validationState.ValidationSkipped)
1483 {
1485 }
1487 }
1488
1490 {
1492 if (_attPresence[s_xsiTypeSO.QualifiedName] == null)
1493 {
1495 }
1496 if (_attPresence[s_xsiNilSO.QualifiedName] == null)
1497 {
1499 }
1500 if (_attPresence[s_xsiSLSO.QualifiedName] == null)
1501 {
1503 }
1504 if (_attPresence[s_xsiNoNsSLSO.QualifiedName] == null)
1505 {
1507 }
1508 }
1509
1510 private SchemaElementDecl FastGetElementDecl(XmlQualifiedName elementName, object particle)
1511 {
1513 if (particle != null)
1514 {
1516 {
1517 schemaElementDecl = xmlSchemaElement.ElementDecl;
1518 }
1519 else
1520 {
1522 _processContents = xmlSchemaAny.ProcessContentsCorrect;
1523 }
1524 }
1526 {
1527 if (_isRoot && _partialValidationType != null)
1528 {
1530 {
1532 if (elementName.Equals(xmlSchemaElement2.QualifiedName))
1533 {
1535 }
1536 else
1537 {
1538 SendValidationEvent(System.SR.Sch_SchemaElementNameMismatch, elementName.ToString(), xmlSchemaElement2.QualifiedName.ToString());
1539 }
1540 }
1542 {
1544 schemaElementDecl = xmlSchemaType.ElementDecl;
1545 }
1546 else
1547 {
1549 }
1550 }
1551 else
1552 {
1554 }
1555 }
1556 return schemaElementDecl;
1557 }
1558
1560 {
1562 if (xsiType != null)
1563 {
1564 object typedValue = null;
1565 Exception ex = s_dtQName.TryParseValue(xsiType, _nameTable, _nsResolver, out typedValue);
1566 if (ex != null)
1567 {
1568 SendValidationEvent(System.SR.Sch_InvalidValueDetailedAttribute, new string[4] { "type", xsiType, s_dtQName.TypeCodeString, ex.Message }, ex);
1569 }
1570 else
1571 {
1573 }
1574 }
1575 if (elementDecl != null)
1576 {
1577 if (elementDecl.IsNillable)
1578 {
1579 if (xsiNil != null)
1580 {
1582 if (_context.IsNill && elementDecl.Presence == SchemaDeclBase.Use.Fixed)
1583 {
1585 }
1586 }
1587 }
1588 else if (xsiNil != null)
1589 {
1591 }
1592 }
1593 if (xmlQualifiedName.IsEmpty)
1594 {
1595 if (elementDecl != null && elementDecl.IsAbstract)
1596 {
1598 elementDecl = null;
1599 }
1600 }
1601 else
1602 {
1606 {
1607 severity = XmlSeverityType.Error;
1608 }
1609 if (schemaElementDecl == null && xmlQualifiedName.Namespace == _nsXs)
1610 {
1612 if (xmlSchemaType == null)
1613 {
1615 }
1616 if (xmlSchemaType != null)
1617 {
1618 schemaElementDecl = xmlSchemaType.ElementDecl;
1619 }
1620 }
1621 if (schemaElementDecl == null)
1622 {
1624 elementDecl = null;
1625 }
1626 else
1627 {
1628 declFound = true;
1629 if (schemaElementDecl.IsAbstract)
1630 {
1632 elementDecl = null;
1633 }
1634 else if (elementDecl != null && !XmlSchemaType.IsDerivedFrom(schemaElementDecl.SchemaType, elementDecl.SchemaType, elementDecl.Block))
1635 {
1637 {
1638 xmlQualifiedName.ToString(),
1639 QNameString(_context.LocalName, _context.Namespace)
1640 });
1641 elementDecl = null;
1642 }
1643 else
1644 {
1645 if (elementDecl != null)
1646 {
1652 }
1655 }
1656 }
1657 }
1658 return elementDecl;
1659 }
1660
1679
1687
1699
1701 {
1702 SchemaAttDef value = null;
1703 if (Ref.Equal(attQName.Namespace, _nsXml) && (_validationFlags & XmlSchemaValidationFlags.AllowXmlAttributes) != 0)
1704 {
1706 {
1708 }
1710 }
1711 return value;
1712 }
1713
1722
1724 {
1726 if (_context.IsNill)
1727 {
1728 return null;
1729 }
1730 if (elementValue.Length == 0)
1731 {
1732 _context.IsDefault = true;
1733 return elementDecl.DefaultValueTyped;
1734 }
1736 if (schemaDeclBase.Presence == SchemaDeclBase.Use.Fixed && !elementValue.Equals(elementDecl.DefaultValueRaw))
1737 {
1739 }
1740 return elementValue;
1741 }
1742
1743 private void LoadSchema(string uri, string url)
1744 {
1745 XmlReader xmlReader = null;
1746 try
1747 {
1749 Stream input = (Stream)_xmlResolver.GetEntity(uri2, null, null);
1755 while (xmlReader.Read())
1756 {
1757 }
1758 }
1759 catch (XmlSchemaException ex)
1760 {
1761 SendValidationEvent(System.SR.Sch_CannotLoadSchema, new string[2] { uri, ex.Message }, ex);
1762 }
1763 catch (Exception ex2)
1764 {
1765 SendValidationEvent(System.SR.Sch_CannotLoadSchema, new string[2] { uri, ex2.Message }, ex2, XmlSeverityType.Warning);
1766 }
1767 finally
1768 {
1769 xmlReader?.Close();
1770 }
1771 }
1772
1773 [MemberNotNull("_compiledSchemaInfo")]
1774 internal void RecompileSchemaSet()
1775 {
1777 {
1778 try
1779 {
1781 }
1782 catch (XmlSchemaException e)
1783 {
1785 }
1786 }
1788 }
1789
1790 private void ProcessTokenizedType(XmlTokenizedType ttype, string name, bool attrValue)
1791 {
1792 switch (ttype)
1793 {
1794 case XmlTokenizedType.ID:
1796 {
1797 break;
1798 }
1799 if (FindId(name) != null)
1800 {
1801 if (attrValue)
1802 {
1803 _attrValid = false;
1804 }
1806 }
1807 else
1808 {
1809 if (_IDs == null)
1810 {
1811 _IDs = new Hashtable();
1812 }
1813 _IDs.Add(name, _context.LocalName);
1814 }
1815 break;
1816 case XmlTokenizedType.IDREF:
1818 {
1819 object obj = FindId(name);
1820 if (obj == null)
1821 {
1823 }
1824 }
1825 break;
1826 case XmlTokenizedType.ENTITY:
1827 ProcessEntity(name);
1828 break;
1829 case XmlTokenizedType.IDREFS:
1830 break;
1831 }
1832 }
1833
1835 {
1836 object typedValue = null;
1837 XmlSchemaDatatype datatype = attdef.Datatype;
1838 string text = value as string;
1839 Exception ex = null;
1840 if (text != null)
1841 {
1842 ex = datatype.TryParseValue(text, _nameTable, _nsResolver, out typedValue);
1843 if (ex == null)
1844 {
1845 goto IL_0050;
1846 }
1847 }
1848 else
1849 {
1850 ex = datatype.TryParseValue(value, _nameTable, _nsResolver, out typedValue);
1851 if (ex == null)
1852 {
1853 goto IL_0050;
1854 }
1855 }
1856 _attrValid = false;
1857 if (text == null)
1858 {
1860 }
1862 {
1863 attdef.Name.ToString(),
1864 text,
1865 GetTypeName(attdef),
1866 ex.Message
1867 }, ex);
1868 return null;
1869 IL_0050:
1870 if (!attdef.CheckValue(typedValue))
1871 {
1872 _attrValid = false;
1874 }
1875 return typedValue;
1876 }
1877
1878 private object CheckElementValue(string stringValue)
1879 {
1880 object typedValue = null;
1882 XmlSchemaDatatype datatype = elementDecl.Datatype;
1884 if (ex != null)
1885 {
1887 {
1888 QNameString(_context.LocalName, _context.Namespace),
1889 stringValue,
1890 GetTypeName(elementDecl),
1891 ex.Message
1892 }, ex);
1893 return null;
1894 }
1895 if (!elementDecl.CheckValue(typedValue))
1896 {
1898 }
1899 return typedValue;
1900 }
1901
1902 private void CheckTokenizedTypes(XmlSchemaDatatype dtype, object typedValue, bool attrValue)
1903 {
1904 if (typedValue == null)
1905 {
1906 return;
1907 }
1908 XmlTokenizedType tokenizedType = dtype.TokenizedType;
1910 {
1911 return;
1912 }
1913 if (dtype.Variety == XmlSchemaDatatypeVariety.List)
1914 {
1915 string[] array = (string[])typedValue;
1916 for (int i = 0; i < array.Length; i++)
1917 {
1918 ProcessTokenizedType(dtype.TokenizedType, array[i], attrValue);
1919 }
1920 }
1921 else
1922 {
1923 ProcessTokenizedType(dtype.TokenizedType, (string)typedValue, attrValue);
1924 }
1925 }
1926
1927 private object FindId(string name)
1928 {
1929 if (_IDs != null)
1930 {
1931 return _IDs[name];
1932 }
1933 return null;
1934 }
1935
1936 private void CheckForwardRefs()
1937 {
1939 while (idRefNode != null)
1940 {
1941 if (FindId(idRefNode.Id) == null)
1942 {
1944 }
1945 IdRefNode next = idRefNode.Next;
1946 idRefNode.Next = null;
1947 idRefNode = next;
1948 }
1949 _idRefListHead = null;
1950 }
1951
1953 {
1954 if (!ValidStates[(int)_currentState, (int)toState])
1955 {
1956 object[] args;
1957 if (_currentState == ValidatorState.None)
1958 {
1960 args = new string[2]
1961 {
1962 methodName,
1963 s_methodNames[1]
1964 };
1966 }
1968 args = new string[2]
1969 {
1972 };
1974 }
1976 }
1977
1978 private void ClearPSVI()
1979 {
1980 if (_textValue != null)
1981 {
1983 }
1985 _wildID = null;
1986 }
1987
1989 {
1991 foreach (SchemaAttDef value in attDefs.Values)
1992 {
1993 if (_attPresence[value.Name] == null && (value.Presence == SchemaDeclBase.Use.Required || value.Presence == SchemaDeclBase.Use.RequiredFixed))
1994 {
1996 }
1997 }
1998 }
1999
2015
2017 {
2019 string text = null;
2021 {
2022 string strA = _nameTable.Add(item.Value);
2023 if (Ref.Equal(strA, attributeNS))
2024 {
2025 text = item.Key;
2026 if (text.Length != 0)
2027 {
2028 return text;
2029 }
2030 }
2031 }
2032 return text;
2033 }
2034
2036 {
2038 _context.Constr = new ConstraintStruct[elementDecl.Constraints.Length];
2039 int num = 0;
2040 for (int i = 0; i < elementDecl.Constraints.Length; i++)
2041 {
2042 _context.Constr[num++] = new ConstraintStruct(elementDecl.Constraints[i]);
2043 }
2044 for (int j = 0; j < _context.Constr.Length; j++)
2045 {
2047 {
2048 continue;
2049 }
2050 bool flag = false;
2052 {
2053 if (((ValidationState)_validationStack[num2]).Constr != null)
2054 {
2056 for (int k = 0; k < constr.Length; k++)
2057 {
2058 if (constr[k].constraint.name == _context.Constr[j].constraint.refer)
2059 {
2060 flag = true;
2061 if (constr[k].keyrefTable == null)
2062 {
2063 constr[k].keyrefTable = new Hashtable();
2064 }
2065 _context.Constr[j].qualifiedTable = constr[k].keyrefTable;
2066 break;
2067 }
2068 }
2069 if (flag)
2070 {
2071 break;
2072 }
2073 }
2074 }
2075 if (!flag)
2076 {
2078 }
2079 }
2080 if (_startIDConstraint == -1)
2081 {
2083 }
2084 }
2085
2087 {
2089 string localName = _context.LocalName;
2090 string @namespace = _context.Namespace;
2091 for (int i = _startIDConstraint; i < _validationStack.Length; i++)
2092 {
2093 if (((ValidationState)_validationStack[i]).Constr == null)
2094 {
2095 continue;
2096 }
2097 ConstraintStruct[] constr = ((ValidationState)_validationStack[i]).Constr;
2098 for (int j = 0; j < constr.Length; j++)
2099 {
2100 if (constr[j].axisSelector.MoveToStartElement(localName, @namespace))
2101 {
2102 constr[j].axisSelector.PushKS(_positionInfo.LineNumber, _positionInfo.LinePosition);
2103 }
2104 for (int k = 0; k < constr[j].axisFields.Count; k++)
2105 {
2107 if (locatedActiveAxis.MoveToStartElement(localName, @namespace) && elementDecl != null)
2108 {
2109 if (elementDecl.Datatype == null || elementDecl.ContentValidator.ContentType == XmlSchemaContentType.Mixed)
2110 {
2111 SendValidationEvent(System.SR.Sch_FieldSimpleTypeExpected, localName);
2112 }
2113 else
2114 {
2115 locatedActiveAxis.isMatched = true;
2116 }
2117 }
2118 }
2119 }
2120 }
2121 }
2122
2123 private void AttributeIdentityConstraints(string name, string ns, object obj, string sobj, XmlSchemaDatatype datatype)
2124 {
2125 for (int i = _startIDConstraint; i < _validationStack.Length; i++)
2126 {
2127 if (((ValidationState)_validationStack[i]).Constr == null)
2128 {
2129 continue;
2130 }
2132 for (int j = 0; j < constr.Length; j++)
2133 {
2134 for (int k = 0; k < constr[j].axisFields.Count; k++)
2135 {
2137 if (locatedActiveAxis.MoveToAttribute(name, ns))
2138 {
2139 if (locatedActiveAxis.Ks[locatedActiveAxis.Column] != null)
2140 {
2142 }
2143 else
2144 {
2145 locatedActiveAxis.Ks[locatedActiveAxis.Column] = new TypedObject(obj, sobj, datatype);
2146 }
2147 }
2148 }
2149 }
2150 }
2151 }
2152
2153 private void EndElementIdentityConstraints(object typedValue, string stringValue, XmlSchemaDatatype datatype)
2154 {
2155 string localName = _context.LocalName;
2156 string @namespace = _context.Namespace;
2157 for (int num = _validationStack.Length - 1; num >= _startIDConstraint; num--)
2158 {
2159 if (((ValidationState)_validationStack[num]).Constr != null)
2160 {
2161 ConstraintStruct[] constr = ((ValidationState)_validationStack[num]).Constr;
2162 for (int i = 0; i < constr.Length; i++)
2163 {
2164 for (int j = 0; j < constr[i].axisFields.Count; j++)
2165 {
2167 if (locatedActiveAxis.isMatched)
2168 {
2169 locatedActiveAxis.isMatched = false;
2170 if (locatedActiveAxis.Ks[locatedActiveAxis.Column] != null)
2171 {
2172 SendValidationEvent(System.SR.Sch_FieldSingleValueExpected, localName);
2173 }
2175 {
2176 if (typedValue != null && stringValue.Length != 0)
2177 {
2178 locatedActiveAxis.Ks[locatedActiveAxis.Column] = new TypedObject(typedValue, stringValue, datatype);
2179 }
2180 }
2181 else if (typedValue != null)
2182 {
2183 locatedActiveAxis.Ks[locatedActiveAxis.Column] = new TypedObject(typedValue, stringValue, datatype);
2184 }
2185 }
2186 locatedActiveAxis.EndElement(localName, @namespace);
2187 }
2188 if (!constr[i].axisSelector.EndElement(localName, @namespace))
2189 {
2190 continue;
2191 }
2192 KeySequence keySequence = constr[i].axisSelector.PopKS();
2193 switch (constr[i].constraint.Role)
2194 {
2196 if (!keySequence.IsQualified())
2197 {
2198 SendValidationEvent(new XmlSchemaValidationException(System.SR.Sch_MissingKey, constr[i].constraint.name.ToString(), _sourceUriString, keySequence.PosLine, keySequence.PosCol));
2199 }
2200 else if (constr[i].qualifiedTable.Contains(keySequence))
2201 {
2202 SendValidationEvent(new XmlSchemaValidationException(System.SR.Sch_DuplicateKey, new string[2]
2203 {
2204 keySequence.ToString(),
2205 constr[i].constraint.name.ToString()
2206 }, _sourceUriString, keySequence.PosLine, keySequence.PosCol));
2207 }
2208 else
2209 {
2210 constr[i].qualifiedTable.Add(keySequence, keySequence);
2211 }
2212 break;
2214 if (keySequence.IsQualified())
2215 {
2216 if (constr[i].qualifiedTable.Contains(keySequence))
2217 {
2218 SendValidationEvent(new XmlSchemaValidationException(System.SR.Sch_DuplicateKey, new string[2]
2219 {
2220 keySequence.ToString(),
2221 constr[i].constraint.name.ToString()
2222 }, _sourceUriString, keySequence.PosLine, keySequence.PosCol));
2223 }
2224 else
2225 {
2226 constr[i].qualifiedTable.Add(keySequence, keySequence);
2227 }
2228 }
2229 break;
2231 if (constr[i].qualifiedTable != null && keySequence.IsQualified() && !constr[i].qualifiedTable.Contains(keySequence))
2232 {
2233 constr[i].qualifiedTable.Add(keySequence, keySequence);
2234 }
2235 break;
2236 }
2237 }
2238 }
2239 }
2240 ConstraintStruct[] constr2 = ((ValidationState)_validationStack[_validationStack.Length - 1]).Constr;
2241 if (constr2 == null)
2242 {
2243 return;
2244 }
2245 for (int k = 0; k < constr2.Length; k++)
2246 {
2247 if (constr2[k].constraint.Role == CompiledIdentityConstraint.ConstraintRole.Keyref || constr2[k].keyrefTable == null)
2248 {
2249 continue;
2250 }
2251 foreach (KeySequence key in constr2[k].keyrefTable.Keys)
2252 {
2253 if (!constr2[k].qualifiedTable.Contains(key))
2254 {
2255 SendValidationEvent(new XmlSchemaValidationException(System.SR.Sch_UnresolvedKeyref, new string[2]
2256 {
2257 key.ToString(),
2258 constr2[k].constraint.name.ToString()
2259 }, _sourceUriString, key.PosLine, key.PosCol));
2260 }
2261 }
2262 }
2263 }
2264
2265 private static void BuildXsiAttributes()
2266 {
2267 if (s_xsiTypeSO == null)
2268 {
2270 xmlSchemaAttribute.Name = "type";
2271 xmlSchemaAttribute.SetQualifiedName(new XmlQualifiedName("type", "http://www.w3.org/2001/XMLSchema-instance"));
2274 }
2275 if (s_xsiNilSO == null)
2276 {
2279 xmlSchemaAttribute2.SetQualifiedName(new XmlQualifiedName("nil", "http://www.w3.org/2001/XMLSchema-instance"));
2282 }
2283 if (s_xsiSLSO == null)
2284 {
2287 xmlSchemaAttribute3.Name = "schemaLocation";
2288 xmlSchemaAttribute3.SetQualifiedName(new XmlQualifiedName("schemaLocation", "http://www.w3.org/2001/XMLSchema-instance"));
2289 xmlSchemaAttribute3.SetAttributeType(builtInSimpleType);
2291 }
2292 if (s_xsiNoNsSLSO == null)
2293 {
2296 xmlSchemaAttribute4.Name = "noNamespaceSchemaLocation";
2297 xmlSchemaAttribute4.SetQualifiedName(new XmlQualifiedName("noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance"));
2298 xmlSchemaAttribute4.SetAttributeType(builtInSimpleType2);
2300 }
2301 }
2302
2303 internal static void ElementValidationError(XmlQualifiedName name, ValidationState context, ValidationEventHandler eventHandler, object sender, string sourceUri, int lineNo, int linePos, XmlSchemaSet schemaSet)
2304 {
2305 ArrayList arrayList = null;
2306 if (context.ElementDecl == null)
2307 {
2308 return;
2309 }
2313 {
2314 bool flag = schemaSet != null;
2315 arrayList = ((!flag) ? contentValidator.ExpectedElements(context, isRequiredOnly: false) : contentValidator.ExpectedParticles(context, isRequiredOnly: false, schemaSet));
2316 if (arrayList == null || arrayList.Count == 0)
2317 {
2318 if (context.TooComplex)
2319 {
2321 {
2322 BuildElementName(context.LocalName, context.Namespace),
2323 BuildElementName(name),
2324 System.SR.Sch_ComplexContentModel
2325 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2326 }
2327 else
2328 {
2330 {
2331 BuildElementName(context.LocalName, context.Namespace),
2332 BuildElementName(name)
2333 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2334 }
2335 }
2336 else if (context.TooComplex)
2337 {
2339 {
2340 BuildElementName(context.LocalName, context.Namespace),
2341 BuildElementName(name),
2342 PrintExpectedElements(arrayList, flag),
2343 System.SR.Sch_ComplexContentModel
2344 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2345 }
2346 else
2347 {
2349 {
2350 BuildElementName(context.LocalName, context.Namespace),
2351 BuildElementName(name),
2352 PrintExpectedElements(arrayList, flag)
2353 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2354 }
2355 }
2356 else if (contentType == XmlSchemaContentType.Empty)
2357 {
2359 {
2360 QNameString(context.LocalName, context.Namespace),
2361 name.ToString()
2362 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2363 }
2364 else if (!contentValidator.IsOpen)
2365 {
2367 {
2368 QNameString(context.LocalName, context.Namespace),
2369 name.ToString()
2370 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2371 }
2372 }
2373
2374 internal static void CompleteValidationError(ValidationState context, ValidationEventHandler eventHandler, object sender, string sourceUri, int lineNo, int linePos, XmlSchemaSet schemaSet)
2375 {
2376 ArrayList arrayList = null;
2377 bool flag = schemaSet != null;
2378 if (context.ElementDecl != null)
2379 {
2381 }
2382 if (arrayList == null || arrayList.Count == 0)
2383 {
2384 if (context.TooComplex)
2385 {
2387 {
2388 BuildElementName(context.LocalName, context.Namespace),
2389 System.SR.Sch_ComplexContentModel
2390 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2391 }
2393 }
2394 else if (context.TooComplex)
2395 {
2397 {
2398 BuildElementName(context.LocalName, context.Namespace),
2399 PrintExpectedElements(arrayList, flag),
2400 System.SR.Sch_ComplexContentModel
2401 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2402 }
2403 else
2404 {
2406 {
2407 BuildElementName(context.LocalName, context.Namespace),
2408 PrintExpectedElements(arrayList, flag)
2409 }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
2410 }
2411 }
2412
2414 {
2415 if (getParticles)
2416 {
2418 object[] args = new string[1] { " " };
2424 if (expected.Count == 1)
2425 {
2427 }
2428 else
2429 {
2430 for (int i = 1; i < expected.Count; i++)
2431 {
2435 if (qualifiedName.Namespace != xmlSchemaParticle2.GetQualifiedName().Namespace)
2436 {
2439 arrayList.Clear();
2440 stringBuilder.Append(value);
2441 }
2442 else
2443 {
2445 }
2446 }
2447 }
2448 arrayList.Add(xmlSchemaParticle2.GetQualifiedName());
2450 return stringBuilder.ToString();
2451 }
2452 return PrintNames(expected);
2453 }
2454
2455 private static string PrintNames(ArrayList expected)
2456 {
2458 stringBuilder.Append('\'');
2459 stringBuilder.Append(expected[0].ToString());
2460 for (int i = 1; i < expected.Count; i++)
2461 {
2462 stringBuilder.Append(' ');
2463 stringBuilder.Append(expected[i].ToString());
2464 }
2465 stringBuilder.Append('\'');
2466 return stringBuilder.ToString();
2467 }
2468
2470 {
2472 if (expected.Count == 1)
2473 {
2474 if (xmlQualifiedName.Name == "*")
2475 {
2477 }
2478 else if (xmlQualifiedName.Namespace.Length != 0)
2479 {
2481 }
2482 else
2483 {
2485 }
2486 return;
2487 }
2488 bool flag = false;
2489 bool flag2 = true;
2491 for (int i = 0; i < expected.Count; i++)
2492 {
2494 if (xmlQualifiedName.Name == "*")
2495 {
2496 flag = true;
2497 continue;
2498 }
2499 if (flag2)
2500 {
2501 flag2 = false;
2502 }
2503 else
2504 {
2505 stringBuilder.Append(", ");
2506 }
2507 stringBuilder.Append(xmlQualifiedName.Name);
2508 }
2509 if (flag)
2510 {
2511 stringBuilder.Append(", ");
2513 }
2514 else if (xmlQualifiedName.Namespace.Length != 0)
2515 {
2517 }
2518 else
2519 {
2521 }
2522 }
2523
2524 private static void EnumerateAny(StringBuilder builder, string namespaces)
2525 {
2527 if (namespaces == "##any" || namespaces == "##other")
2528 {
2529 stringBuilder.Append(namespaces);
2530 }
2531 else
2532 {
2534 stringBuilder.Append(array[0]);
2535 for (int i = 1; i < array.Length; i++)
2536 {
2537 stringBuilder.Append(", ");
2538 stringBuilder.Append(array[i]);
2539 }
2540 }
2542 }
2543
2544 internal static string QNameString(string localName, string ns)
2545 {
2546 if (ns.Length == 0)
2547 {
2548 return localName;
2549 }
2550 return ns + ":" + localName;
2551 }
2552
2553 internal static string BuildElementName(XmlQualifiedName qname)
2554 {
2555 return BuildElementName(qname.Name, qname.Namespace);
2556 }
2557
2558 internal static string BuildElementName(string localName, string ns)
2559 {
2560 if (ns.Length != 0)
2561 {
2562 return System.SR.Format(System.SR.Sch_ElementNameAndNamespace, localName, ns);
2563 }
2564 return System.SR.Format(System.SR.Sch_ElementName, localName);
2565 }
2566
2567 private void ProcessEntity(string name)
2568 {
2569 if (_checkEntity)
2570 {
2572 if (_dtdSchemaInfo != null)
2573 {
2575 }
2576 if (dtdEntityInfo == null)
2577 {
2579 }
2580 else if (dtdEntityInfo.IsUnparsedEntity)
2581 {
2583 }
2584 }
2585 }
2586
2587 private void SendValidationEvent(string code)
2588 {
2590 }
2591
2596
2601
2606
2614
2619
2624
2629
2637
2639 {
2640 bool flag = false;
2641 if (severity == XmlSeverityType.Error)
2642 {
2643 flag = true;
2645 }
2646 if (flag)
2647 {
2648 if (_eventHandler == null)
2649 {
2650 throw e;
2651 }
2653 }
2654 else if (ReportValidationWarnings && _eventHandler != null)
2655 {
2657 }
2658 }
2659
2660 internal static void SendValidationEvent(ValidationEventHandler eventHandler, object sender, XmlSchemaValidationException e, XmlSeverityType severity)
2661 {
2662 if (eventHandler != null)
2663 {
2664 eventHandler(sender, new ValidationEventArgs(e, severity));
2665 }
2666 else if (severity == XmlSeverityType.Error)
2667 {
2668 throw e;
2669 }
2670 }
2671}
virtual int Add(object? value)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
virtual bool Contains(object key)
Definition Hashtable.cs:719
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 string Sch_InvalidElementContentExpecting
Definition SR.cs:896
static string Sch_SubstitutionBlocked
Definition SR.cs:878
static string Sch_InvalidTextInElementExpecting
Definition SR.cs:894
static string Sch_ValidateElementInvalidCall
Definition SR.cs:1202
static string Sch_UndeclaredEntity
Definition SR.cs:748
static string Sch_NotXsiAttribute
Definition SR.cs:1168
static string Sch_ContentInNill
Definition SR.cs:784
static string Sch_ContinuationString
Definition SR.cs:910
static string Sch_IncompleteContentExpectingComplex
Definition SR.cs:902
static string Sch_InvalidEndElementCallTyped
Definition SR.cs:1188
static string Sch_FixedElementValue
Definition SR.cs:494
static string Sch_UndeclaredId
Definition SR.cs:418
static string Sch_SchemaAttributeNameMismatch
Definition SR.cs:1198
static string Sch_XsiTypeNotFound
Definition SR.cs:602
static string Sch_MoreThanOneWildId
Definition SR.cs:958
static string Sch_InvalidXsiNill
Definition SR.cs:874
static string Sch_SchemaElementNameMismatch
Definition SR.cs:1196
static string Sch_ElementNameAndNamespace
Definition SR.cs:906
static string Sch_InvalidEndValidation
Definition SR.cs:1184
static string Sch_NoAttributeSchemaFound
Definition SR.cs:788
static string Sch_ComponentAlreadySeenForNS
Definition SR.cs:1164
static string Sch_UnresolvedKeyref
Definition SR.cs:732
static string Sch_InvalidEndElementMultiple
Definition SR.cs:1190
static string Sch_FieldSimpleTypeExpected
Definition SR.cs:738
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Sch_SubstitutionNotAllowed
Definition SR.cs:876
static string Sch_AbstractElement
Definition SR.cs:870
static string Sch_InvalidElementContentExpectingComplex
Definition SR.cs:898
static string Sch_RefNotInScope
Definition SR.cs:718
static string Sch_ElementInMixedWithFixed
Definition SR.cs:1072
static string Sch_IncompleteContentExpecting
Definition SR.cs:900
static string Sch_AnyElementNS
Definition SR.cs:912
static string Sch_InvalidTextInEmpty
Definition SR.cs:916
static string Sch_XsiTypeAbstract
Definition SR.cs:604
static string Sch_FixedAttributeValue
Definition SR.cs:492
static string Sch_InvalidStateTransition
Definition SR.cs:1182
static string Sch_ValidateAttributeInvalidCall
Definition SR.cs:1200
static string Sch_DefaultAttributeNotApplied
Definition SR.cs:1166
static string Sch_InvalidEndElementCall
Definition SR.cs:1186
static string Sch_InvalidValueDetailedAttribute
Definition SR.cs:488
static string Sch_InvalidElementDefaultValue
Definition SR.cs:582
static string Sch_NoElementSchemaFound
Definition SR.cs:786
static string Sch_IncompleteContent
Definition SR.cs:890
static string Sch_XsiTypeBlockedEx
Definition SR.cs:872
static string Sch_ProhibitedAttribute
Definition SR.cs:950
static string Sch_XsiNilAndFixed
Definition SR.cs:1120
static string Sch_UndeclaredElement
Definition SR.cs:412
static string Sch_InvalidElementSubstitution
Definition SR.cs:904
static string Sch_DuplicateAttribute
Definition SR.cs:1192
static string Sch_InvalidElementInEmptyEx
Definition SR.cs:880
static string Sch_MissingKey
Definition SR.cs:742
static string Sch_UnparsedEntityRef
Definition SR.cs:750
static string Sch_AttributeValueDataTypeDetailed
Definition SR.cs:496
static string Sch_CannotLoadSchema
Definition SR.cs:1078
static string Sch_DuplicateKey
Definition SR.cs:744
static string Sch_InvalidWhitespaceInEmpty
Definition SR.cs:918
static string Sch_IncompleteContentComplex
Definition SR.cs:892
static string Sch_InvalidPartialValidationType
Definition SR.cs:1194
static string Sch_ElementName
Definition SR.cs:908
static string Sch_AttrUseAndWildId
Definition SR.cs:956
static string Sch_InvalidElementContentComplex
Definition SR.cs:888
static string Sch_FieldSingleValueExpected
Definition SR.cs:740
static string Sch_DupId
Definition SR.cs:410
static string Sch_InvalidTextInElement
Definition SR.cs:884
static string Sch_AnyElement
Definition SR.cs:914
static string Sch_ElementValueDataTypeDetailed
Definition SR.cs:580
static string Sch_InvalidElementContent
Definition SR.cs:886
static string Sch_AllElement
Definition SR.cs:594
static string Sch_UndeclaredAttribute
Definition SR.cs:414
static string Sch_InvalidStartTransition
Definition SR.cs:1180
static string Sch_InvalidElementInTextOnlyEx
Definition SR.cs:882
static string Sch_MissRequiredAttribute
Definition SR.cs:490
Definition SR.cs:7
override string ToString()
StringBuilder Append(char value, int repeatCount)
static int CompareExchange(ref int location1, int value, int comparand)
override string ToString()
Definition Uri.cs:1119
void AddToTop(object o)
Definition HWStack.cs:90
object Push()
Definition HWStack.cs:52
object Peek()
Definition HWStack.cs:81
static bool Equal(string strA, string strB)
Definition Ref.cs:5
CompiledIdentityConstraint constraint
virtual ArrayList ExpectedParticles(ValidationState context, bool isRequiredOnly, XmlSchemaSet schemaSet)
static readonly ContentValidator Any
static void AddParticleToExpected(XmlSchemaParticle p, XmlSchemaSet schemaSet, ArrayList particles)
virtual object ValidateElement(XmlQualifiedName name, ValidationState context, out int errorCode)
static readonly ContentValidator Mixed
virtual ArrayList ExpectedElements(ValidationState context, bool isRequiredOnly)
static XmlSchemaSimpleType GetSimpleTypeFromXsdType(XmlQualifiedName qname)
static XmlSchema GetBuildInSchema()
static readonly SchemaAttDef Empty
CompiledIdentityConstraint[] Constraints
SchemaElementDecl GetElementDecl(XmlQualifiedName qname)
SchemaElementDecl GetTypeDecl(XmlQualifiedName qname)
XmlSchemaElement GetElement(XmlQualifiedName qname)
Dictionary< XmlQualifiedName, SchemaAttDef > AttributeDecls
Definition SchemaInfo.cs:99
SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, XmlSchemaObject partialValidationType, out AttributeMatchState attributeMatchState)
XmlSchemaContentProcessing ProcessContents
Exception TryParseValue(string s, XmlNameTable nameTable, IXmlNamespaceResolver nsmgr, out object typedValue)
static XmlSchemaDatatype FromXmlTokenizedType(XmlTokenizedType token)
static string ConcatenatedToString(object value)
static XmlSchemaDatatype FromXmlTokenizedTypeXsd(XmlTokenizedType token)
virtual XmlSchemaDatatypeVariety Variety
ValidationEventHandler GetEventHandler()
XmlSchemaCompilationSettings CompilationSettings
bool RemoveRecursive(XmlSchema schemaToRemove)
XmlSchemaObjectTable GlobalElements
XmlSchema? Add(string? targetNamespace, string schemaUri)
XmlReaderSettings ReaderSettings
XmlSchema FindSchemaByNSAndUrl(Uri schemaUri, string ns, DictionaryEntry[] locationsTable)
static ? XmlSchemaSimpleType GetBuiltInSimpleType(XmlQualifiedName qualifiedName)
static bool IsDerivedFrom([NotNullWhen(true)] XmlSchemaType? derivedType, [NotNullWhen(true)] XmlSchemaType? baseType, XmlSchemaDerivationMethod except)
static ? XmlSchemaComplexType GetBuiltInComplexType(XmlTypeCode typeCode)
void CheckStateTransition(ValidatorState toState, string methodName)
void CheckRequiredAttributes(SchemaElementDecl currentElementDecl)
void ValidateWhitespace(string elementStringValue, XmlValueGetter elementValueGetter)
static readonly XmlSchemaDatatype s_dtCDATA
XmlSchemaContentProcessing CurrentProcessContents
void SkipToEndElement(XmlSchemaInfo? schemaInfo)
void SetDtdSchemaInfo(IDtdInfo dtdSchemaInfo)
static readonly XmlSchemaDatatype s_dtStringArray
object CheckAttributeValue(object value, SchemaAttDef attdef)
static void ElementValidationError(XmlQualifiedName name, ValidationState context, ValidationEventHandler eventHandler, object sender, string sourceUri, int lineNo, int linePos, XmlSchemaSet schemaSet)
void ValidateElement(string localName, string namespaceUri, XmlSchemaInfo? schemaInfo, string? xsiType, string? xsiNil, string? xsiSchemaLocation, string? xsiNoNamespaceSchemaLocation)
static XmlSchemaAttribute s_xsiNoNsSLSO
XmlSchemaElement GetSubstitutionGroupHead(XmlQualifiedName member)
void SendValidationEvent(XmlSchemaValidationException e)
void ValidateText(XmlValueGetter elementValue)
object ValidateAtomicValue(string stringValue, out XmlSchemaSimpleType memberType)
object ValidateElementContext(XmlQualifiedName elementName, out bool invalidElementInContext)
XmlSchemaValidator(XmlNameTable nameTable, XmlSchemaSet schemas, IXmlNamespaceResolver namespaceResolver, XmlSchemaValidationFlags validationFlags)
static void EnumerateAny(StringBuilder builder, string namespaces)
void ThrowDeclNotFoundWarningOrError(bool declFound)
static void CompleteValidationError(ValidationState context, ValidationEventHandler eventHandler, object sender, string sourceUri, int lineNo, int linePos, XmlSchemaSet schemaSet)
void SendValidationEvent(string code, string[] args)
void ValidateWhitespace(XmlValueGetter elementValue)
void ValidateElement(string localName, string namespaceUri, XmlSchemaInfo? schemaInfo)
object ValidateAtomicValue(object parsedValue, out XmlSchemaSimpleType memberType)
object InternalValidateEndElement(XmlSchemaInfo schemaInfo, object typedValue)
static string PrintNames(ArrayList expected)
object CheckElementValue(string stringValue)
void SendValidationEvent(string code, string[] args, Exception innerException, XmlSeverityType severity)
string GetTypeName(SchemaDeclBase decl)
object ValidateAttribute(string localName, string namespaceUri, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo)
readonly XmlSchemaValidationFlags _validationFlags
void LoadSchema(string uri, string url)
static string BuildElementName(XmlQualifiedName qname)
object? ValidateAttribute(string localName, string namespaceUri, string attributeValue, XmlSchemaInfo? schemaInfo)
void Push(XmlQualifiedName elementName)
object? ValidateAttribute(string localName, string namespaceUri, XmlValueGetter attributeValue, XmlSchemaInfo? schemaInfo)
void SendValidationEvent(string code, string[] args, Exception innerException)
SchemaElementDecl CheckXsiTypeAndNil(SchemaElementDecl elementDecl, string xsiType, string xsiNil, ref bool declFound)
void ProcessSchemaLocations(string xsiSchemaLocation, string xsiNoNamespaceSchemaLocation)
object? ValidateEndElement(XmlSchemaInfo? schemaInfo, object typedValue)
void ValidateText(string elementStringValue, XmlValueGetter elementValueGetter)
static readonly IXmlLineInfo s_dummyPositionInfo
void SendValidationEvent(XmlSchemaValidationException e, XmlSeverityType severity)
SchemaElementDecl FastGetElementDecl(XmlQualifiedName elementName, object particle)
ValidationEventHandler? ValidationEventHandler
void Initialize(XmlSchemaObject partialValidationType)
static string PrintExpectedElements(ArrayList expected, bool getParticles)
void EndElementIdentityConstraints(object typedValue, string stringValue, XmlSchemaDatatype datatype)
void SendValidationEvent(string code, string arg1, string arg2)
static string BuildElementName(string localName, string ns)
string GetDefaultAttributePrefix(string attributeNS)
static void PrintNamesWithNS(ArrayList expected, StringBuilder builder)
void SendValidationEvent(XmlSchemaException e)
object? ValidateEndElement(XmlSchemaInfo? schemaInfo)
static XmlSchemaAttribute s_xsiTypeSO
void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes, bool createNodeData)
void SendValidationEvent(string code, string arg)
void CheckTokenizedTypes(XmlSchemaDatatype dtype, object typedValue, bool attrValue)
void ValidateEndOfAttributes(XmlSchemaInfo? schemaInfo)
void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes)
void SendValidationEvent(string code, string msg, XmlSeverityType severity)
void AttributeIdentityConstraints(string name, string ns, object obj, string sobj, XmlSchemaDatatype datatype)
void ProcessTokenizedType(XmlTokenizedType ttype, string name, bool attrValue)
object CheckMixedValueConstraint(string elementValue)
static void SendValidationEvent(ValidationEventHandler eventHandler, object sender, XmlSchemaValidationException e, XmlSeverityType severity)
static readonly XmlSchemaDatatype s_dtQName
XmlSchemaContentProcessing _processContents
void ValidateWhitespace(string elementValue)
static string QNameString(string localName, string ns)
SchemaAttDef CheckIsXmlAttribute(XmlQualifiedName attQName)
readonly IXmlNamespaceResolver _nsResolver
static bool IsOnlyWhitespace(string str)
static bool ToBoolean(string s)
static string[] SplitString(string value)
string Add(char[] array, int offset, int length)
override bool Equals([NotNullWhen(true)] object? other)
static readonly XmlQualifiedName Empty
void Init(string name, string ns)
static XmlReader Create(string inputUri)
object? GetEntity(Uri absoluteUri, string? role, Type? ofObjectToReturn)
virtual Uri ResolveUri(Uri? baseUri, string? relativeUri)
IDtdEntityInfo LookupEntity(string name)
IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
string? LookupPrefix(string namespaceName)