2 // System.Xml.Schema.XmlSchemaSimpleContent.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.Xml.Serialization;
\r
33 namespace System.Xml.Schema
\r
36 /// Summary description for XmlSchemaSimpleContent.
\r
38 public class XmlSchemaSimpleContent : XmlSchemaContentModel
\r
40 private XmlSchemaContent content;
\r
41 const string xmlname = "simpleContent";
\r
42 public XmlSchemaSimpleContent()
\r
46 [XmlElement("restriction",typeof(XmlSchemaSimpleContentRestriction),Namespace=XmlSchema.Namespace)]
\r
47 [XmlElement("extension",typeof(XmlSchemaSimpleContentExtension),Namespace=XmlSchema.Namespace)]
\r
48 public override XmlSchemaContent Content
\r
50 get{ return content; }
\r
51 set{ content = value; }
\r
55 /// 1. Content must be present and one of restriction or extention
\r
57 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
59 // If this is already compiled this time, simply skip.
\r
60 if (this.IsComplied (schema.CompilationId))
\r
65 error(h, "Content must be present in a simpleContent");
\r
69 if(Content is XmlSchemaSimpleContentRestriction)
\r
71 XmlSchemaSimpleContentRestriction xscr = (XmlSchemaSimpleContentRestriction) Content;
\r
72 errorCount += xscr.Compile(h, schema);
\r
74 else if(Content is XmlSchemaSimpleContentExtension)
\r
76 XmlSchemaSimpleContentExtension xsce = (XmlSchemaSimpleContentExtension) Content;
\r
77 errorCount += xsce.Compile(h, schema);
\r
80 error(h,"simpleContent can't have any value other than restriction or extention");
\r
83 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
84 this.CompilationId = schema.CompilationId;
\r
88 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
90 if (IsValidated (schema.ValidationId))
\r
93 errorCount += this.Content.Validate (h, schema);
\r
95 ValidationId = schema.ValidationId;
\r
100 // {any attributes with non-schema namespace . . .}>
\r
101 // Content: (annotation?, (restriction | extension))
\r
103 internal static XmlSchemaSimpleContent Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
105 XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent();
\r
106 reader.MoveToElement();
\r
108 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
110 error(h,"Should not happen :1: XmlSchemaComplexContent.Read, name="+reader.Name,null);
\r
111 reader.SkipToEnd();
\r
115 simple.LineNumber = reader.LineNumber;
\r
116 simple.LinePosition = reader.LinePosition;
\r
117 simple.SourceUri = reader.BaseURI;
\r
119 while(reader.MoveToNextAttribute())
\r
121 if(reader.Name == "id")
\r
123 simple.Id = reader.Value;
\r
125 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
127 error(h,reader.Name + " is not a valid attribute for simpleContent",null);
\r
131 XmlSchemaUtil.ReadUnhandledAttribute(reader,simple);
\r
135 reader.MoveToElement();
\r
136 if(reader.IsEmptyElement)
\r
138 //Content: (annotation?, (restriction | extension))
\r
140 while(reader.ReadNextElement())
\r
142 if(reader.NodeType == XmlNodeType.EndElement)
\r
144 if(reader.LocalName != xmlname)
\r
145 error(h,"Should not happen :2: XmlSchemaSimpleContent.Read, name="+reader.Name,null);
\r
148 if(level <= 1 && reader.LocalName == "annotation")
\r
150 level = 2; //Only one annotation
\r
151 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
152 if(annotation != null)
\r
153 simple.Annotation = annotation;
\r
158 if(reader.LocalName == "restriction")
\r
161 XmlSchemaSimpleContentRestriction restriction = XmlSchemaSimpleContentRestriction.Read(reader,h);
\r
162 if(restriction != null)
\r
163 simple.content = restriction;
\r
166 if(reader.LocalName == "extension")
\r
169 XmlSchemaSimpleContentExtension extension = XmlSchemaSimpleContentExtension.Read(reader,h);
\r
170 if(extension != null)
\r
171 simple.content = extension;
\r
175 reader.RaiseInvalidElementError();
\r