/
XmlSchemaAny.cs
116 lines (102 loc) · 3.41 KB
/
XmlSchemaAny.cs
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
108
109
110
111
112
113
114
115
116
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
using System.Xml.Serialization;
using System.Text;
namespace System.Xml.Schema
{
public class XmlSchemaAny : XmlSchemaParticle
{
private string? _ns;
private XmlSchemaContentProcessing _processContents = XmlSchemaContentProcessing.None;
private NamespaceList? _namespaceList;
[XmlAttribute("namespace")]
public string? Namespace
{
get { return _ns; }
set { _ns = value; }
}
[XmlAttribute("processContents"), DefaultValue(XmlSchemaContentProcessing.None)]
public XmlSchemaContentProcessing ProcessContents
{
get { return _processContents; }
set { _processContents = value; }
}
[XmlIgnore]
internal NamespaceList? NamespaceList
{
get { return _namespaceList; }
}
[XmlIgnore]
internal string ResolvedNamespace
{
get
{
if (string.IsNullOrEmpty(_ns))
{
return "##any";
}
return _ns;
}
}
[XmlIgnore]
internal XmlSchemaContentProcessing ProcessContentsCorrect
{
get { return _processContents == XmlSchemaContentProcessing.None ? XmlSchemaContentProcessing.Strict : _processContents; }
}
internal override string NameString
{
get
{
switch (_namespaceList!.Type)
{
case NamespaceList.ListType.Any:
return "##any:*";
case NamespaceList.ListType.Other:
return "##other:*";
case NamespaceList.ListType.Set:
StringBuilder sb = new StringBuilder();
int i = 1;
foreach (string wildcardNS in _namespaceList.Enumerate)
{
sb.Append($"{wildcardNS}:*");
if (i < _namespaceList.Enumerate.Count)
{
sb.Append(' ');
}
i++;
}
return sb.ToString();
default:
return string.Empty;
}
}
}
internal void BuildNamespaceList(string? targetNamespace)
{
if (_ns != null)
{ //If namespace="" default to namespace="##any"
_namespaceList = new NamespaceList(_ns, targetNamespace!);
}
else
{
_namespaceList = new NamespaceList();
}
}
internal void BuildNamespaceListV1Compat(string targetNamespace)
{
if (_ns != null)
{
_namespaceList = new NamespaceListV1Compat(_ns, targetNamespace);
}
else
{
_namespaceList = new NamespaceList(); //This is only ##any, hence base class is sufficient
}
}
internal bool Allows(XmlQualifiedName qname)
{
return _namespaceList!.Allows(qname.Namespace);
}
}
}