1 // Author: Dwivedi, Ajay kumar
\r
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;
\r
27 using System.Xml.Serialization;
\r
29 namespace System.Xml.Schema
\r
32 /// Summary description for XmlSchemaAnnotation.
\r
34 public class XmlSchemaAnnotation : XmlSchemaObject
\r
37 private XmlSchemaObjectCollection items;
\r
38 private XmlAttribute[] unhandledAttributes;
\r
39 const string xmlname = "annotation";
\r
41 public XmlSchemaAnnotation()
\r
43 items = new XmlSchemaObjectCollection();
\r
46 [System.Xml.Serialization.XmlAttribute("id", DataType="ID")]
\r
53 [XmlElement("appinfo",typeof(XmlSchemaAppInfo))]
\r
54 [XmlElement("documentation",typeof(XmlSchemaDocumentation))]
\r
55 public XmlSchemaObjectCollection Items
\r
57 get{ return items; }
\r
61 public XmlAttribute[] UnhandledAttributes
\r
65 if(unhandledAttributeList != null)
\r
67 unhandledAttributes = (XmlAttribute[]) unhandledAttributeList.ToArray(typeof(XmlAttribute));
\r
68 unhandledAttributeList = null;
\r
70 return unhandledAttributes;
\r
74 unhandledAttributes = value;
\r
75 unhandledAttributeList = null;
\r
79 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
81 // If this is already compiled this time, simply skip.
\r
82 if (CompilationId == schema.CompilationId)
\r
85 this.CompilationId = schema.CompilationId;
\r
89 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
96 // {any attributes with non-schema namespace . . .}>
\r
97 // Content: (appinfo | documentation)*
\r
99 internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
101 XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
\r
102 reader.MoveToElement();
\r
104 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
106 error(h,"Should not happen :1: XmlSchemaAnnotation.Read, name="+reader.Name,null);
\r
107 reader.SkipToEnd();
\r
111 annotation.LineNumber = reader.LineNumber;
\r
112 annotation.LinePosition = reader.LinePosition;
\r
113 annotation.SourceUri = reader.BaseURI;
\r
116 while(reader.MoveToNextAttribute())
\r
118 if(reader.Name == "id")
\r
120 annotation.Id = reader.Value;
\r
122 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
124 error(h,reader.Name + " is not a valid attribute for annotation",null);
\r
128 XmlSchemaUtil.ReadUnhandledAttribute(reader,annotation);
\r
132 reader.MoveToElement();
\r
133 if(reader.IsEmptyElement)
\r
136 //Content: (appinfo | documentation)*
\r
138 string expectedEnd = null;
\r
144 reader.ReadNextElement();
\r
146 if(reader.NodeType == XmlNodeType.EndElement)
\r
149 string expected = xmlname;
\r
150 if(expectedEnd != null)
\r
152 expected = expectedEnd;
\r
153 expectedEnd = null;
\r
156 if(reader.LocalName != expected)
\r
157 error(h,"Should not happen :2: XmlSchemaAnnotation.Read, name="+reader.Name+",expected="+expected,null);
\r
163 if(reader.LocalName == "appinfo")
\r
165 XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader,h,out skip);
\r
166 if(appinfo != null)
\r
167 annotation.items.Add(appinfo);
\r
170 if(reader.LocalName == "documentation")
\r
172 XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader,h, out skip);
\r
173 if(documentation != null)
\r
174 annotation.items.Add(documentation);
\r
177 reader.RaiseInvalidElementError();
\r