1 // Author: Dwivedi, Ajay kumar
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 using System.Collections;
27 using System.Xml.Serialization;
29 namespace System.Xml.Schema
32 /// Summary description for XmlSchemaAnnotation.
34 public class XmlSchemaAnnotation : XmlSchemaObject
37 private XmlSchemaObjectCollection items;
38 private XmlAttribute[] unhandledAttributes;
39 const string xmlname = "annotation";
41 public XmlSchemaAnnotation()
43 items = new XmlSchemaObjectCollection();
46 [System.Xml.Serialization.XmlAttribute("id", DataType="ID")]
53 [XmlElement("appinfo",typeof(XmlSchemaAppInfo))]
54 [XmlElement("documentation",typeof(XmlSchemaDocumentation))]
55 public XmlSchemaObjectCollection Items
61 public XmlAttribute[] UnhandledAttributes
65 if(unhandledAttributeList != null)
67 unhandledAttributes = (XmlAttribute[]) unhandledAttributeList.ToArray(typeof(XmlAttribute));
68 unhandledAttributeList = null;
70 return unhandledAttributes;
74 unhandledAttributes = value;
75 unhandledAttributeList = null;
79 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
81 // If this is already compiled this time, simply skip.
82 if (CompilationId == schema.CompilationId)
85 this.CompilationId = schema.CompilationId;
89 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
96 // {any attributes with non-schema namespace . . .}>
97 // Content: (appinfo | documentation)*
99 internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
101 XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
102 reader.MoveToElement();
104 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
106 error(h,"Should not happen :1: XmlSchemaAnnotation.Read, name="+reader.Name,null);
111 annotation.LineNumber = reader.LineNumber;
112 annotation.LinePosition = reader.LinePosition;
113 annotation.SourceUri = reader.BaseURI;
116 while(reader.MoveToNextAttribute())
118 if(reader.Name == "id")
120 annotation.Id = reader.Value;
122 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
124 error(h,reader.Name + " is not a valid attribute for annotation",null);
128 XmlSchemaUtil.ReadUnhandledAttribute(reader,annotation);
132 reader.MoveToElement();
133 if(reader.IsEmptyElement)
136 //Content: (appinfo | documentation)*
138 string expectedEnd = null;
144 reader.ReadNextElement();
146 if(reader.NodeType == XmlNodeType.EndElement)
149 string expected = xmlname;
150 if(expectedEnd != null)
152 expected = expectedEnd;
156 if(reader.LocalName != expected)
157 error(h,"Should not happen :2: XmlSchemaAnnotation.Read, name="+reader.Name+",expected="+expected,null);
163 if(reader.LocalName == "appinfo")
165 XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader,h,out skip);
167 annotation.items.Add(appinfo);
170 if(reader.LocalName == "documentation")
172 XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader,h, out skip);
173 if(documentation != null)
174 annotation.items.Add(documentation);
177 reader.RaiseInvalidElementError();