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