2 // System.Xml.Schema.XmlSchemaComplexContent.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 XmlSchemaComplexContent.
\r
38 public class XmlSchemaComplexContent : XmlSchemaContentModel
\r
40 private XmlSchemaContent content;
\r
41 private bool isMixed;
\r
42 const string xmlname = "complexContent";
\r
44 public XmlSchemaComplexContent()
\r
47 [System.Xml.Serialization.XmlAttribute("mixed")]
\r
48 public bool IsMixed
\r
50 get{ return isMixed; }
\r
51 set{ isMixed = value; }
\r
54 [XmlElement("restriction",typeof(XmlSchemaComplexContentRestriction),Namespace=XmlSchema.Namespace)]
\r
55 [XmlElement("extension",typeof(XmlSchemaComplexContentExtension),Namespace=XmlSchema.Namespace)]
\r
56 public override XmlSchemaContent Content
\r
58 get{ return content; }
\r
59 set{ content = value; }
\r
63 /// 1. Content must be present
\r
65 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
67 // If this is already compiled this time, simply skip.
\r
68 if (this.IsComplied (schema.CompilationId))
\r
72 if (Content != null)
\r
73 Content.Parent = this;
\r
76 if (isRedefinedComponent) {
\r
77 if (Annotation != null)
\r
78 Annotation.isRedefinedComponent = true;
\r
79 if (Content != null)
\r
80 Content.isRedefinedComponent = true;
\r
85 error(h, "Content must be present in a complexContent");
\r
89 if(Content is XmlSchemaComplexContentRestriction)
\r
91 XmlSchemaComplexContentRestriction xscr = (XmlSchemaComplexContentRestriction) Content;
\r
92 errorCount += xscr.Compile(h, schema);
\r
94 else if(Content is XmlSchemaComplexContentExtension)
\r
96 XmlSchemaComplexContentExtension xsce = (XmlSchemaComplexContentExtension) Content;
\r
97 errorCount += xsce.Compile(h, schema);
\r
100 error(h,"complexContent can't have any value other than restriction or extention");
\r
103 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
105 this.CompilationId = schema.CompilationId;
\r
109 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
111 if (IsValidated (schema.ValidationId))
\r
114 errorCount += Content.Validate (h, schema);
\r
116 ValidationId = schema.ValidationId;
\r
122 // {any attributes with non-schema namespace . . .}>
\r
123 // Content: (annotation?, (restriction | extension))
\r
124 //</complexContent>
\r
125 internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
127 XmlSchemaComplexContent complex = new XmlSchemaComplexContent();
\r
128 reader.MoveToElement();
\r
130 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
132 error(h,"Should not happen :1: XmlSchemaComplexContent.Read, name="+reader.Name,null);
\r
137 complex.LineNumber = reader.LineNumber;
\r
138 complex.LinePosition = reader.LinePosition;
\r
139 complex.SourceUri = reader.BaseURI;
\r
141 while(reader.MoveToNextAttribute())
\r
143 if(reader.Name == "id")
\r
145 complex.Id = reader.Value;
\r
147 else if(reader.Name == "mixed")
\r
150 complex.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);
\r
151 if(innerex != null)
\r
152 error(h,reader.Value + " is an invalid value for mixed",innerex);
\r
154 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
156 error(h,reader.Name + " is not a valid attribute for complexContent",null);
\r
160 XmlSchemaUtil.ReadUnhandledAttribute(reader,complex);
\r
164 reader.MoveToElement();
\r
165 if(reader.IsEmptyElement)
\r
167 //Content: (annotation?, (restriction | extension))
\r
169 while(reader.ReadNextElement())
\r
171 if(reader.NodeType == XmlNodeType.EndElement)
\r
173 if(reader.LocalName != xmlname)
\r
174 error(h,"Should not happen :2: XmlSchemaComplexContent.Read, name="+reader.Name,null);
\r
177 if(level <= 1 && reader.LocalName == "annotation")
\r
179 level = 2; //Only one annotation
\r
180 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
181 if(annotation != null)
\r
182 complex.Annotation = annotation;
\r
187 if(reader.LocalName == "restriction")
\r
190 XmlSchemaComplexContentRestriction restriction = XmlSchemaComplexContentRestriction.Read(reader,h);
\r
191 if(restriction != null)
\r
192 complex.content = restriction;
\r
195 if(reader.LocalName == "extension")
\r
198 XmlSchemaComplexContentExtension extension = XmlSchemaComplexContentExtension.Read(reader,h);
\r
199 if(extension != null)
\r
200 complex.content = extension;
\r
204 reader.RaiseInvalidElementError();
\r