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
.Xml
.Serialization
;
28 namespace System
.Xml
.Schema
31 /// Summary description for XmlSchemaNotation.
33 public class XmlSchemaNotation
: XmlSchemaAnnotated
37 private string system
;
38 private XmlQualifiedName qualifiedName
;
39 const string xmlname
= "notation";
41 public XmlSchemaNotation()
44 [System
.Xml
.Serialization
.XmlAttribute("name")]
50 [System
.Xml
.Serialization
.XmlAttribute("public")]
56 [System
.Xml
.Serialization
.XmlAttribute("system")]
60 set{ system = value; }
64 internal XmlQualifiedName QualifiedName
66 get{ return qualifiedName;}
69 // 1. name and public must be present
70 // public and system must be anyURI
71 internal override int Compile(ValidationEventHandler h
, XmlSchema schema
)
73 // If this is already compiled this time, simply skip.
74 if (CompilationId
== schema
.CompilationId
)
78 error(h
,"Required attribute name must be present");
79 else if(!XmlSchemaUtil
.CheckNCName(this.name
))
80 error(h
,"attribute name must be NCName");
82 qualifiedName
= new XmlQualifiedName(Name
, AncestorSchema
.TargetNamespace
);
85 error(h
,"public must be present");
86 else if(!XmlSchemaUtil
.CheckAnyUri(Public
))
87 error(h
,"public must be anyURI");
89 if(system
!= null && !XmlSchemaUtil
.CheckAnyUri(system
))
90 error(h
,"system must be present and of Type anyURI");
92 XmlSchemaUtil
.CompileID(Id
,this,schema
.IDCollection
,h
);
97 internal override int Validate(ValidationEventHandler h
, XmlSchema schema
)
107 // {any attributes with non-schema namespace . . .}>
108 // Content: (annotation?)
110 internal static XmlSchemaNotation
Read(XmlSchemaReader reader
, ValidationEventHandler h
)
112 XmlSchemaNotation notation
= new XmlSchemaNotation();
113 reader
.MoveToElement();
115 if(reader
.NamespaceURI
!= XmlSchema
.Namespace
|| reader
.LocalName
!= xmlname
)
117 error(h
,"Should not happen :1: XmlSchemaInclude.Read, name="+reader
.Name
,null);
122 notation
.LineNumber
= reader
.LineNumber
;
123 notation
.LinePosition
= reader
.LinePosition
;
124 notation
.SourceUri
= reader
.BaseURI
;
126 while(reader
.MoveToNextAttribute())
128 if(reader
.Name
== "id")
130 notation
.Id
= reader
.Value
;
132 else if(reader
.Name
== "name")
134 notation
.name
= reader
.Value
;
136 else if(reader
.Name
== "public")
138 notation
.pub
= reader
.Value
;
140 else if(reader
.Name
== "system")
142 notation
.system
= reader
.Value
;
144 else if((reader
.NamespaceURI
== "" && reader
.Name
!= "xmlns") || reader
.NamespaceURI
== XmlSchema
.Namespace
)
146 error(h
,reader
.Name
+ " is not a valid attribute for notation",null);
150 XmlSchemaUtil
.ReadUnhandledAttribute(reader
,notation
);
154 reader
.MoveToElement();
155 if(reader
.IsEmptyElement
)
158 // Content: (annotation?)
160 while(reader
.ReadNextElement())
162 if(reader
.NodeType
== XmlNodeType
.EndElement
)
164 if(reader
.LocalName
!= xmlname
)
165 error(h
,"Should not happen :2: XmlSchemaNotation.Read, name="+reader
.Name
,null);
168 if(level
<= 1 && reader
.LocalName
== "annotation")
170 level
= 2; //Only one annotation
171 XmlSchemaAnnotation annotation
= XmlSchemaAnnotation
.Read(reader
,h
);
172 if(annotation
!= null)
173 notation
.Annotation
= annotation
;
176 reader
.RaiseInvalidElementError();