2 // System.Xml.Schema.XmlSchemaAny.cs
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System
.Collections
;
31 using System
.Collections
.Specialized
;
33 using System
.Xml
.Serialization
;
34 using System
.ComponentModel
;
35 using Mono
.Xml
.Schema
;
37 namespace System
.Xml
.Schema
40 /// Summary description for XmlSchemaAny.
42 public class XmlSchemaAny
: XmlSchemaParticle
44 static XmlSchemaAny anyTypeContent
;
45 internal static XmlSchemaAny AnyTypeContent
{
47 if (anyTypeContent
== null) {
48 anyTypeContent
= new XmlSchemaAny ();
49 anyTypeContent
.MaxOccursString
= "unbounded";
50 anyTypeContent
.MinOccurs
= 0;
51 anyTypeContent
.CompileOccurence (null, null);
52 anyTypeContent
.Namespace
= "##any";
53 anyTypeContent
.wildcard
.HasValueAny
= true;
54 anyTypeContent
.wildcard
.ResolvedNamespaces
= new StringCollection ();
55 // Although it is not documented by W3C, but it should be.
56 anyTypeContent
.wildcard
.ResolvedProcessing
=
57 anyTypeContent
.ProcessContents
= XmlSchemaContentProcessing
.Lax
;
59 return anyTypeContent
;
63 private string nameSpace
;
64 private XmlSchemaContentProcessing processing
;
65 const string xmlname
= "any";
67 private XsdWildcard wildcard
;
71 wildcard
= new XsdWildcard (this);
74 [System
.Xml
.Serialization
.XmlAttribute("namespace")]
75 public string Namespace
77 get{ return nameSpace; }
78 set{ nameSpace = value; }
81 [DefaultValue(XmlSchemaContentProcessing
.None
)]
82 [System
.Xml
.Serialization
.XmlAttribute("processContents")]
83 public XmlSchemaContentProcessing ProcessContents
85 get{ return processing; }
86 set{ processing = value; }
89 // Post Compilation Schema Infoset
90 internal bool HasValueAny
{
91 get { return wildcard.HasValueAny; }
94 internal bool HasValueLocal
{
95 get { return wildcard.HasValueLocal; }
98 internal bool HasValueOther
{
99 get { return wildcard.HasValueOther; }
102 internal bool HasValueTargetNamespace
{
103 get { return wildcard.HasValueTargetNamespace; }
106 internal StringCollection ResolvedNamespaces
{
107 get { return wildcard.ResolvedNamespaces; }
110 internal XmlSchemaContentProcessing ResolvedProcessContents
112 get{ return wildcard.ResolvedProcessing; }
115 internal string TargetNamespace
117 get { return wildcard.TargetNamespace; }
121 /// 1. id must be of type ID
122 /// 2. namespace can have one of the following values:
123 /// a) ##any or ##other
124 /// b) list of anyURI and ##targetNamespace and ##local
126 internal override int Compile(ValidationEventHandler h
, XmlSchema schema
)
128 // If this is already compiled this time, simply skip.
129 if (this.IsComplied (schema
.CompilationId
))
134 XmlSchemaUtil
.CompileID(Id
,this, schema
.IDCollection
,h
);
135 wildcard
.TargetNamespace
= schema
.TargetNamespace
;
136 if (wildcard
.TargetNamespace
== null)
137 wildcard
.TargetNamespace
= "";
138 CompileOccurence (h
, schema
);
140 wildcard
.Compile (Namespace
, h
, schema
);
142 if (processing
== XmlSchemaContentProcessing
.None
)
143 wildcard
.ResolvedProcessing
= XmlSchemaContentProcessing
.Strict
;
145 wildcard
.ResolvedProcessing
= processing
;
147 this.CompilationId
= schema
.CompilationId
;
151 internal override XmlSchemaParticle
GetOptimizedParticle (bool isTop
)
153 if (OptimizedParticle
!= null)
154 return OptimizedParticle
;
155 // Uncommenting this causes incorrect validation.
156 // It will prevent UPA e.g. msxsdtest/Particles/particlesJf006.xsd
157 // if (ValidatedMaxOccurs == 0) {
158 // OptimizedParticle = XmlSchemaParticle.Empty;
159 // return OptimizedParticle;
162 XmlSchemaAny any
= new XmlSchemaAny ();
164 any
.CompileOccurence (null, null);
165 any
.wildcard
= this.wildcard
;
166 OptimizedParticle
= any
;
168 // properties which never contribute to validation
169 any
.Namespace
= Namespace
;
170 any
.ProcessContents
= ProcessContents
;
171 any
.Annotation
= Annotation
;
172 any
.UnhandledAttributes
= UnhandledAttributes
;
174 return OptimizedParticle
;
177 internal override int Validate(ValidationEventHandler h
, XmlSchema schema
)
182 internal override bool ParticleEquals (XmlSchemaParticle other
)
184 XmlSchemaAny any
= other
as XmlSchemaAny
;
187 if (this.HasValueAny
!= any
.HasValueAny
||
188 this.HasValueLocal
!= any
.HasValueLocal
||
189 this.HasValueOther
!= any
.HasValueOther
||
190 this.HasValueTargetNamespace
!= any
.HasValueTargetNamespace
||
191 this.ResolvedProcessContents
!= any
.ResolvedProcessContents
||
192 this.ValidatedMaxOccurs
!= any
.ValidatedMaxOccurs
||
193 this.ValidatedMinOccurs
!= any
.ValidatedMinOccurs
||
194 this.ResolvedNamespaces
.Count
!= any
.ResolvedNamespaces
.Count
)
196 for (int i
= 0; i
< ResolvedNamespaces
.Count
; i
++)
197 if (ResolvedNamespaces
[i
] != any
.ResolvedNamespaces
[i
])
203 // 3.8.6. Attribute Wildcard Intersection
204 // Only try to examine if their intersection is expressible, and
205 // returns if the result is empty.
206 internal bool ExamineAttributeWildcardIntersection (XmlSchemaAny other
,
207 ValidationEventHandler h
, XmlSchema schema
)
209 return wildcard
.ExamineAttributeWildcardIntersection (other
, h
, schema
);
212 internal override bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle
,
213 ValidationEventHandler h
, XmlSchema schema
, bool raiseError
)
215 XmlSchemaAny baseAny
= baseParticle
as XmlSchemaAny
;
216 if (baseAny
== null) {
218 error (h
, "Invalid particle derivation by restriction was found.");
221 // 3.9.6 Particle Derivation OK (Any:Any - NSSubset)
222 if (!ValidateOccurenceRangeOK (baseParticle
, h
, schema
, raiseError
))
224 return wildcard
.ValidateWildcardSubset (baseAny
.wildcard
, h
, schema
, raiseError
);
228 internal override void CheckRecursion (int depth
, ValidationEventHandler h
, XmlSchema schema
)
233 internal override void ValidateUniqueParticleAttribution (
234 XmlSchemaObjectTable qnames
, ArrayList nsNames
,
235 ValidationEventHandler h
, XmlSchema schema
)
237 // Wildcard Intersection check.
238 foreach (XmlSchemaAny other
in nsNames
)
239 if (!ExamineAttributeWildcardIntersection (other
, h
, schema
))
240 error (h
, "Ambiguous -any- particle was found.");
244 internal override void ValidateUniqueTypeAttribution (XmlSchemaObjectTable labels
,
245 ValidationEventHandler h
, XmlSchema schema
)
250 // 3.10.4 Wildcard Allows Namespace Name. (In fact it is almost copy...)
251 internal bool ValidateWildcardAllowsNamespaceName (string ns
,
252 ValidationEventHandler h
, XmlSchema schema
, bool raiseError
)
254 return wildcard
.ValidateWildcardAllowsNamespaceName (ns
, h
, schema
, raiseError
);
259 // maxOccurs = (nonNegativeInteger | unbounded) : 1
260 // minOccurs = nonNegativeInteger : 1
261 // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
262 // processContents = (lax | skip | strict) : strict
263 // {any attributes with non-schema namespace . . .}>
264 // Content: (annotation?)
266 internal static XmlSchemaAny
Read(XmlSchemaReader reader
, ValidationEventHandler h
)
268 XmlSchemaAny any
= new XmlSchemaAny();
269 reader
.MoveToElement();
271 if(reader
.NamespaceURI
!= XmlSchema
.Namespace
|| reader
.LocalName
!= xmlname
)
273 error(h
,"Should not happen :1: XmlSchemaAny.Read, name="+reader
.Name
,null);
278 any
.LineNumber
= reader
.LineNumber
;
279 any
.LinePosition
= reader
.LinePosition
;
280 any
.SourceUri
= reader
.BaseURI
;
282 while(reader
.MoveToNextAttribute())
284 if(reader
.Name
== "id")
286 any
.Id
= reader
.Value
;
288 else if(reader
.Name
== "maxOccurs")
292 any
.MaxOccursString
= reader
.Value
;
296 error(h
,reader
.Value
+ " is an invalid value for maxOccurs",e
);
299 else if(reader
.Name
== "minOccurs")
303 any
.MinOccursString
= reader
.Value
;
307 error(h
,reader
.Value
+ " is an invalid value for minOccurs", e
);
310 else if(reader
.Name
== "namespace")
312 any
.nameSpace
= reader
.Value
;
314 else if(reader
.Name
== "processContents")
317 any
.processing
= XmlSchemaUtil
.ReadProcessingAttribute(reader
,out innerex
);
319 error(h
, reader
.Value
+ " is not a valid value for processContents",innerex
);
321 else if((reader
.NamespaceURI
== "" && reader
.Name
!= "xmlns") || reader
.NamespaceURI
== XmlSchema
.Namespace
)
323 error(h
,reader
.Name
+ " is not a valid attribute for any",null);
327 XmlSchemaUtil
.ReadUnhandledAttribute(reader
,any
);
331 reader
.MoveToElement();
332 if(reader
.IsEmptyElement
)
335 // Content: (annotation?)
337 while(reader
.ReadNextElement())
339 if(reader
.NodeType
== XmlNodeType
.EndElement
)
341 if(reader
.LocalName
!= xmlname
)
342 error(h
,"Should not happen :2: XmlSchemaAny.Read, name="+reader
.Name
,null);
345 if(level
<= 1 && reader
.LocalName
== "annotation")
347 level
= 2; //Only one annotation
348 XmlSchemaAnnotation annotation
= XmlSchemaAnnotation
.Read(reader
,h
);
349 if(annotation
!= null)
350 any
.Annotation
= annotation
;
353 reader
.RaiseInvalidElementError();