Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SchemaHelper.cs
Go to the documentation of this file.
2using System.Xml;
4
6
7internal static class SchemaHelper
8{
9 internal static bool NamespacesEqual(string ns1, string ns2)
10 {
11 if (ns1 == null || ns1.Length == 0)
12 {
13 if (ns2 != null)
14 {
15 return ns2.Length == 0;
16 }
17 return true;
18 }
19 return ns1 == ns2;
20 }
21
23 {
24 outSchema = null;
25 ICollection collection = schemas.Schemas();
26 string @namespace = typeQName.Namespace;
27 foreach (XmlSchema item in collection)
28 {
29 if (!NamespacesEqual(@namespace, item.TargetNamespace))
30 {
31 continue;
32 }
34 foreach (XmlSchemaObject item2 in item.Items)
35 {
37 {
38 return xmlSchemaType;
39 }
40 }
41 }
42 return null;
43 }
44
46 {
47 outSchema = null;
48 ICollection collection = schemas.Schemas();
49 string @namespace = elementQName.Namespace;
50 foreach (XmlSchema item in collection)
51 {
52 if (!NamespacesEqual(@namespace, item.TargetNamespace))
53 {
54 continue;
55 }
57 foreach (XmlSchemaObject item2 in item.Items)
58 {
60 {
61 return xmlSchemaElement;
62 }
63 }
64 }
65 return null;
66 }
67
68 internal static XmlSchema GetSchema(string ns, XmlSchemaSet schemas)
69 {
70 if (ns == null)
71 {
72 ns = string.Empty;
73 }
74 ICollection collection = schemas.Schemas();
75 foreach (XmlSchema item in collection)
76 {
77 if ((item.TargetNamespace == null && ns.Length == 0) || ns.Equals(item.TargetNamespace))
78 {
79 return item;
80 }
81 }
82 return CreateSchema(ns, schemas);
83 }
84
85 private static XmlSchema CreateSchema(string ns, XmlSchemaSet schemas)
86 {
89 if (ns.Length > 0)
90 {
92 xmlSchema.Namespaces.Add("tns", ns);
93 }
94 schemas.Add(xmlSchema);
95 return xmlSchema;
96 }
97
98 internal static void AddElementForm(XmlSchemaElement element, XmlSchema schema)
99 {
100 if (schema.ElementFormDefault != XmlSchemaForm.Qualified)
101 {
102 element.Form = XmlSchemaForm.Qualified;
103 }
104 }
105
106 internal static void AddSchemaImport(string ns, XmlSchema schema)
107 {
108 if (NamespacesEqual(ns, schema.TargetNamespace) || NamespacesEqual(ns, "http://www.w3.org/2001/XMLSchema") || NamespacesEqual(ns, "http://www.w3.org/2001/XMLSchema-instance"))
109 {
110 return;
111 }
112 foreach (XmlSchemaObject include in schema.Includes)
113 {
115 {
116 return;
117 }
118 }
120 if (ns != null && ns.Length > 0)
121 {
123 }
124 schema.Includes.Add(xmlSchemaImport);
125 }
126}
static XmlSchema GetSchema(string ns, XmlSchemaSet schemas)
static XmlSchemaElement GetSchemaElement(XmlSchemaSet schemas, XmlQualifiedName elementQName, out XmlSchema outSchema)
static XmlSchemaType GetSchemaType(XmlSchemaSet schemas, XmlQualifiedName typeQName, out XmlSchema outSchema)
static XmlSchema CreateSchema(string ns, XmlSchemaSet schemas)
static void AddSchemaImport(string ns, XmlSchema schema)
static bool NamespacesEqual(string ns1, string ns2)
static void AddElementForm(XmlSchemaElement element, XmlSchema schema)
XmlSchema? Add(string? targetNamespace, string schemaUri)