blob: a18d39a6b1b9021cdfe485cd5317eb9e1f1403b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
//------------------------------------------------------------------------------
// <copyright file="AutoValidator.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
namespace System.Xml.Schema {
using System.Diagnostics;
using System.Globalization;
#pragma warning disable 618
internal class AutoValidator : BaseValidator {
const string x_schema = "x-schema";
public AutoValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) : base(reader, schemaCollection, eventHandling) {
schemaInfo = new SchemaInfo();
}
public override bool PreserveWhitespace {
get { return false; }
}
public override void Validate() {
ValidationType valType = DetectValidationType();
switch(valType) {
case ValidationType.XDR:
reader.Validator = new XdrValidator(this);
reader.Validator.Validate();
break;
case ValidationType.Schema:
reader.Validator = new XsdValidator(this);
reader.Validator.Validate();
break;
case ValidationType.Auto:
break;
}
}
public override void CompleteValidation() {}
public override object FindId(string name) {
return null;
}
private ValidationType DetectValidationType() {
//Type not yet detected : Check in Schema Collection
if (reader.Schemas != null && reader.Schemas.Count > 0) {
XmlSchemaCollectionEnumerator enumerator = reader.Schemas.GetEnumerator();
while (enumerator.MoveNext()) {
XmlSchemaCollectionNode node = enumerator.CurrentNode;
SchemaInfo schemaInfo = node.SchemaInfo;
if(schemaInfo.SchemaType == SchemaType.XSD)
return ValidationType.Schema;
else if(schemaInfo.SchemaType == SchemaType.XDR)
return ValidationType.XDR;
}
}
if (reader.NodeType == XmlNodeType.Element) {
SchemaType schemaType = SchemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
if (schemaType == SchemaType.XSD) {
return ValidationType.Schema;
}
else if (schemaType == SchemaType.XDR) {
return ValidationType.XDR;
}
else {
int count = reader.AttributeCount;
for (int i = 0; i < count ; i++) {
reader.MoveToAttribute(i);
string objectNs = reader.NamespaceURI;
string objectName = reader.LocalName;
if (Ref.Equal(objectNs, SchemaNames.NsXmlNs)) {
if(XdrBuilder.IsXdrSchema(reader.Value)) {
reader.MoveToElement();
return ValidationType.XDR;
}
}
else if (Ref.Equal(objectNs, SchemaNames.NsXsi)) {
reader.MoveToElement();
return ValidationType.Schema;
}
else if (Ref.Equal(objectNs, SchemaNames.QnDtDt.Namespace) && Ref.Equal(objectName, SchemaNames.QnDtDt.Name)) {
reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value);
reader.MoveToElement();
return ValidationType.XDR;
}
} //end of for
if(count > 0) {
reader.MoveToElement();
}
}
}
return ValidationType.Auto;
}
}
#pragma warning restore 618
}
|