Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XNodeValidator.cs
Go to the documentation of this file.
4
5namespace System.Xml.Schema;
6
7internal sealed class XNodeValidator
8{
9 private readonly XmlSchemaSet schemas;
10
11 private readonly ValidationEventHandler validationEventHandler;
12
13 private XObject source;
14
15 private bool addSchemaInfo;
16
18
20
22
24
25 private readonly XName xsiTypeName;
26
27 private readonly XName xsiNilName;
28
30 {
33 XNamespace xNamespace = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance");
34 xsiTypeName = xNamespace.GetName("type");
35 xsiNilName = xNamespace.GetName("nil");
36 }
37
39 {
43 XmlNodeType nodeType = source.NodeType;
44 if (nodeType != XmlNodeType.Element)
45 {
46 if (nodeType != XmlNodeType.Attribute)
47 {
48 if (nodeType != XmlNodeType.Document)
49 {
50 goto IL_0066;
51 }
52 source = ((XDocument)source).Root;
53 if (source == null)
54 {
56 }
57 xmlSchemaValidationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
58 }
59 else
60 {
61 if (((XAttribute)source).IsNamespaceDeclaration)
62 {
63 goto IL_0066;
64 }
65 if (source.Parent == null)
66 {
68 }
69 }
70 }
76 if (partialValidationType != null)
77 {
79 }
80 else
81 {
83 }
85 if (nodeType == XmlNodeType.Attribute)
86 {
88 }
89 else
90 {
92 }
95 return;
96 IL_0066:
98 }
99
101 {
104 xmlSchemaInfo.IsNil = false;
106 XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType)(xmlSchemaInfo.SchemaType = sa.AttributeSchemaType);
107 if (xmlSchemaSimpleType.Datatype.Variety == XmlSchemaDatatypeVariety.Union)
108 {
112 {
113 object obj = null;
114 try
115 {
117 }
118 catch (XmlSchemaException)
119 {
120 }
121 if (obj != null)
122 {
124 break;
125 }
126 }
127 }
129 return xmlSchemaInfo;
130 }
131
133 {
136 if (!refName.IsEmpty)
137 {
139 if (xmlSchemaAttribute == null)
140 {
141 return null;
142 }
143 }
144 string fixedValue = xmlSchemaAttribute.FixedValue;
145 if (fixedValue != null)
146 {
147 return fixedValue;
148 }
149 return xmlSchemaAttribute.DefaultValue;
150 }
151
153 {
156 if (!refName.IsEmpty)
157 {
159 if (xmlSchemaElement == null)
160 {
161 return null;
162 }
163 }
164 string fixedValue = xmlSchemaElement.FixedValue;
165 if (fixedValue != null)
166 {
167 return fixedValue;
168 }
169 return xmlSchemaElement.DefaultValue;
170 }
171
172 private void ReplaceSchemaInfo(XObject o, XmlSchemaInfo schemaInfo)
173 {
174 if (schemaInfos == null)
175 {
177 }
178 XmlSchemaInfo value = o.Annotation<XmlSchemaInfo>();
179 if (value != null)
180 {
182 {
184 }
185 o.RemoveAnnotations<XmlSchemaInfo>();
186 }
187 if (!schemaInfos.TryGetValue(schemaInfo, out value))
188 {
189 value = schemaInfo;
191 }
192 o.AddAnnotation(value);
193 }
194
196 {
197 while (e != null)
198 {
200 if (xAttribute != null)
201 {
202 do
203 {
204 xAttribute = xAttribute.next;
205 if (xAttribute.IsNamespaceDeclaration)
206 {
207 string text = xAttribute.Name.LocalName;
208 if (text == "xmlns")
209 {
210 text = string.Empty;
211 }
213 {
215 }
216 }
217 }
218 while (xAttribute != e.lastAttr);
219 }
220 e = e.parent as XElement;
221 }
222 }
223
224 private void PushElement(XElement e, ref string xsiType, ref string xsiNil)
225 {
228 if (xAttribute == null)
229 {
230 return;
231 }
232 do
233 {
234 xAttribute = xAttribute.next;
235 if (xAttribute.IsNamespaceDeclaration)
236 {
237 string text = xAttribute.Name.LocalName;
238 if (text == "xmlns")
239 {
240 text = string.Empty;
241 }
243 continue;
244 }
245 XName name = xAttribute.Name;
246 if (name == xsiTypeName)
247 {
248 xsiType = xAttribute.Value;
249 }
250 else if (name == xsiNilName)
251 {
252 xsiNil = xAttribute.Value;
253 }
254 }
255 while (xAttribute != e.lastAttr);
256 }
257
264
269
271 {
273 XmlSchemaInfo schemaInfo = (addSchemaInfo ? new XmlSchemaInfo() : null);
274 source = a;
275 validator.ValidateAttribute(a.Name.LocalName, a.Name.NamespaceName, a.Value, schemaInfo);
276 if (addSchemaInfo)
277 {
278 ReplaceSchemaInfo(a, schemaInfo);
279 }
281 }
282
284 {
287 if (xAttribute != null)
288 {
289 do
290 {
291 xAttribute = xAttribute.next;
292 if (!xAttribute.IsNamespaceDeclaration)
293 {
295 }
296 }
297 while (xAttribute != e.lastAttr);
298 source = e;
299 }
300 if (addSchemaInfo)
301 {
302 if (defaultAttributes == null)
303 {
305 }
306 else
307 {
309 }
312 {
313 xAttribute = new XAttribute(XNamespace.Get(defaultAttribute.QualifiedName.Namespace).GetName(defaultAttribute.QualifiedName.Name), GetDefaultValue(defaultAttribute));
315 e.Add(xAttribute);
316 }
317 }
319 }
320
345
346 private void ValidateNodes(XElement e)
347 {
350 if (xNode != null)
351 {
352 do
353 {
354 xNode = xNode.next;
355 if (xNode is XElement e2)
356 {
358 }
359 else if (xNode is XText xText)
360 {
361 string value = xText.Value;
362 if (value.Length > 0)
363 {
366 }
367 }
368 }
369 while (xNode != e.content);
370 source = e;
371 }
372 else if (e.content is string { Length: >0 } text)
373 {
375 }
377 }
378
379 private void ValidationCallback(object sender, ValidationEventArgs e)
380 {
381 if (validationEventHandler != null)
382 {
384 }
385 else if (e.Severity == XmlSeverityType.Error)
386 {
387 throw e.Exception;
388 }
389 }
390}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static string InvalidOperation_MissingParent
Definition SR.cs:54
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidOperation_MissingRoot
Definition SR.cs:56
static string InvalidOperation_BadNodeType
Definition SR.cs:70
Definition SR.cs:7
void Add(object? content)
string NamespaceName
Definition XName.cs:18
static XNamespace Get(string namespaceName)
Definition XNamespace.cs:51
XmlNodeType NodeType
Definition XObject.cs:51
XmlNamespaceManager namespaceManager
Dictionary< XmlSchemaInfo, XmlSchemaInfo > schemaInfos
void RestoreLineInfo(IXmlLineInfo originalLineInfo)
readonly ValidationEventHandler validationEventHandler
XNodeValidator(XmlSchemaSet schemas, ValidationEventHandler validationEventHandler)
readonly XmlSchemaSet schemas
void ReplaceSchemaInfo(XObject o, XmlSchemaInfo schemaInfo)
IXmlLineInfo SaveLineInfo(XObject source)
void ValidationCallback(object sender, ValidationEventArgs e)
XmlSchemaInfo GetDefaultAttributeSchemaInfo(XmlSchemaAttribute sa)
string GetDefaultValue(XmlSchemaElement se)
string GetDefaultValue(XmlSchemaAttribute sa)
void Validate(XObject source, XmlSchemaObject partialValidationType, bool addSchemaInfo)
void PushElement(XElement e, ref string xsiType, ref string xsiNil)
XmlSchemaObjectTable GlobalElements
XmlSchemaObjectTable GlobalAttributes
void ValidateElement(string localName, string namespaceUri, XmlSchemaInfo? schemaInfo)
object? ValidateAttribute(string localName, string namespaceUri, string attributeValue, XmlSchemaInfo? schemaInfo)
object? ValidateEndElement(XmlSchemaInfo? schemaInfo)
void ValidateEndOfAttributes(XmlSchemaInfo? schemaInfo)
void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes)
virtual bool HasNamespace(string prefix)
virtual void AddNamespace(string prefix, string uri)