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.
26 using System.Xml.Serialization;
28 namespace System.Xml.Schema
31 /// Summary description for XmlSchemaImport.
33 public class XmlSchemaImport : XmlSchemaExternal
35 private XmlSchemaAnnotation annotation;
36 private string nameSpace;
37 const string xmlname = "import";
39 public XmlSchemaImport()
43 [System.Xml.Serialization.XmlAttribute("namespace", DataType="anyURI")]
44 public string Namespace
46 get{ return nameSpace; }
47 set{ nameSpace = value; }
50 [XmlElement("annotation", Type=typeof (XmlSchemaAnnotation))]
51 public XmlSchemaAnnotation Annotation
53 get{ return annotation; }
54 set{ annotation = value; }
59 // schemaLocation = anyURI
60 // {any attributes with non-schema namespace . . .}>
61 // Content: (annotation?)
63 internal static XmlSchemaImport Read(XmlSchemaReader reader, ValidationEventHandler h)
65 XmlSchemaImport import = new XmlSchemaImport();
66 reader.MoveToElement();
68 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != "import")
70 error(h,"Should not happen :1: XmlSchemaImport.Read, name="+reader.Name,null);
75 import.LineNumber = reader.LineNumber;
76 import.LinePosition = reader.LinePosition;
77 import.SourceUri = reader.BaseURI;
79 while(reader.MoveToNextAttribute())
81 if(reader.Name == "id")
83 import.Id = reader.Value;
85 else if(reader.Name == "namespace")
87 import.nameSpace = reader.Value;
89 else if(reader.Name == "schemaLocation")
91 import.SchemaLocation = reader.Value;
93 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
95 error(h,reader.Name + " is not a valid attribute for import",null);
99 XmlSchemaUtil.ReadUnhandledAttribute(reader,import);
103 reader.MoveToElement();
104 if(reader.IsEmptyElement)
107 // Content: (annotation?)
109 while(reader.ReadNextElement())
111 if(reader.NodeType == XmlNodeType.EndElement)
113 if(reader.LocalName != xmlname)
114 error(h,"Should not happen :2: XmlSchemaImport.Read, name="+reader.Name,null);
117 if(level <= 1 && reader.LocalName == "annotation")
119 level = 2; //Only one annotation
120 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
121 if(annotation != null)
122 import.Annotation = annotation;
125 reader.RaiseInvalidElementError();