2 // System.Xml.Schema.XmlSchemaAnyAttribute.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
.ComponentModel
;
34 using System
.Xml
.Serialization
;
35 using Mono
.Xml
.Schema
;
37 namespace System
.Xml
.Schema
40 /// Summary description for XmlSchemaAnyAttribute.
42 public class XmlSchemaAnyAttribute
: XmlSchemaAnnotated
44 private string nameSpace
;
45 private XmlSchemaContentProcessing processing
;
46 const string xmlname
= "anyAttribute";
47 private XsdWildcard wildcard
;
49 public XmlSchemaAnyAttribute()
51 wildcard
= new XsdWildcard (this);
54 [System
.Xml
.Serialization
.XmlAttribute("namespace")]
55 public string Namespace
57 get{ return nameSpace; }
58 set{ nameSpace = value; }
61 [DefaultValue(XmlSchemaContentProcessing
.None
)]
62 [System
.Xml
.Serialization
.XmlAttribute("processContents")]
63 public XmlSchemaContentProcessing ProcessContents
65 get{ return processing; }
66 set{ processing = value; }
70 internal bool HasValueAny
{
71 get { return wildcard.HasValueAny; }
74 internal bool HasValueLocal
{
75 get { return wildcard.HasValueLocal; }
78 internal bool HasValueOther
{
79 get { return wildcard.HasValueOther; }
82 internal bool HasValueTargetNamespace
{
83 get { return wildcard.HasValueTargetNamespace; }
86 internal StringCollection ResolvedNamespaces
{
87 get { return wildcard.ResolvedNamespaces; }
90 internal XmlSchemaContentProcessing ResolvedProcessContents
92 get{ return wildcard.ResolvedProcessing; }
95 internal string TargetNamespace
97 get { return wildcard.TargetNamespace; }
101 /// 1. id must be of type ID
102 /// 2. namespace can have one of the following values:
103 /// a) ##any or ##other
104 /// b) list of anyURI and ##targetNamespace and ##local
106 internal override int Compile(ValidationEventHandler h
, XmlSchema schema
)
108 // If this is already compiled this time, simply skip.
109 if (this.IsComplied (schema
.CompilationId
))
114 wildcard
.TargetNamespace
= schema
.TargetNamespace
;
115 if (wildcard
.TargetNamespace
== null)
116 wildcard
.TargetNamespace
= "";
118 XmlSchemaUtil
.CompileID(Id
,this, schema
.IDCollection
,h
);
120 wildcard
.Compile (Namespace
, h
, schema
);
122 if (processing
== XmlSchemaContentProcessing
.None
)
123 wildcard
.ResolvedProcessing
= XmlSchemaContentProcessing
.Strict
;
125 wildcard
.ResolvedProcessing
= processing
;
127 this.CompilationId
= schema
.CompilationId
;
131 internal override int Validate(ValidationEventHandler h
, XmlSchema schema
)
136 // 3.10.6 Wildcard Subset
137 internal void ValidateWildcardSubset (XmlSchemaAnyAttribute other
,
138 ValidationEventHandler h
, XmlSchema schema
)
140 wildcard
.ValidateWildcardSubset (other
.wildcard
, h
, schema
);
144 internal bool ValidateWildcardAllowsNamespaceName (string ns
, XmlSchema schema
)
146 return wildcard
.ValidateWildcardAllowsNamespaceName (ns
, null, schema
, false);
151 // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
152 // processContents = (lax | skip | strict) : strict
153 // {any attributes with non-schema namespace . . .}>
154 // Content: (annotation?)
156 internal static XmlSchemaAnyAttribute
Read(XmlSchemaReader reader
, ValidationEventHandler h
)
158 XmlSchemaAnyAttribute any
= new XmlSchemaAnyAttribute();
159 reader
.MoveToElement();
161 if(reader
.NamespaceURI
!= XmlSchema
.Namespace
|| reader
.LocalName
!= xmlname
)
163 error(h
,"Should not happen :1: XmlSchemaAnyAttribute.Read, name="+reader
.Name
,null);
168 any
.LineNumber
= reader
.LineNumber
;
169 any
.LinePosition
= reader
.LinePosition
;
170 any
.SourceUri
= reader
.BaseURI
;
172 while(reader
.MoveToNextAttribute())
174 if(reader
.Name
== "id")
176 any
.Id
= reader
.Value
;
178 else if(reader
.Name
== "namespace")
180 any
.nameSpace
= reader
.Value
;
182 else if(reader
.Name
== "processContents")
185 any
.processing
= XmlSchemaUtil
.ReadProcessingAttribute(reader
,out innerex
);
187 error(h
, reader
.Value
+ " is not a valid value for processContents",innerex
);
189 else if((reader
.NamespaceURI
== "" && reader
.Name
!= "xmlns") || reader
.NamespaceURI
== XmlSchema
.Namespace
)
191 error(h
,reader
.Name
+ " is not a valid attribute for anyAttribute",null);
195 XmlSchemaUtil
.ReadUnhandledAttribute(reader
,any
);
199 reader
.MoveToElement();
200 if(reader
.IsEmptyElement
)
203 // Content: (annotation?)
205 while(reader
.ReadNextElement())
207 if(reader
.NodeType
== XmlNodeType
.EndElement
)
209 if(reader
.LocalName
!= xmlname
)
210 error(h
,"Should not happen :2: XmlSchemaAnyAttribute.Read, name="+reader
.Name
,null);
213 if(level
<= 1 && reader
.LocalName
== "annotation")
215 level
= 2; //Only one annotation
216 XmlSchemaAnnotation annotation
= XmlSchemaAnnotation
.Read(reader
,h
);
217 if(annotation
!= null)
218 any
.Annotation
= annotation
;
221 reader
.RaiseInvalidElementError();