2 // System.Xml.Schema.XmlSchemaComplexContent.cs
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
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
;
33 namespace System
.Xml
.Schema
36 /// Summary description for XmlSchemaComplexContent.
38 public class XmlSchemaComplexContent
: XmlSchemaContentModel
40 private XmlSchemaContent content
;
42 const string xmlname
= "complexContent";
44 public XmlSchemaComplexContent()
47 [System
.Xml
.Serialization
.XmlAttribute("mixed")]
50 get{ return isMixed; }
51 set{ isMixed = value; }
54 [XmlElement("restriction",typeof(XmlSchemaComplexContentRestriction
))]
55 [XmlElement("extension",typeof(XmlSchemaComplexContentExtension
))]
56 public override XmlSchemaContent Content
58 get{ return content; }
59 set{ content = value; }
62 internal override void SetParent (XmlSchemaObject parent
)
64 base.SetParent (parent
);
66 Content
.SetParent (this);
70 /// 1. Content must be present
72 internal override int Compile(ValidationEventHandler h
, XmlSchema schema
)
74 // If this is already compiled this time, simply skip.
75 if (CompilationId
== schema
.CompilationId
)
78 if (isRedefinedComponent
) {
79 if (Annotation
!= null)
80 Annotation
.isRedefinedComponent
= true;
82 Content
.isRedefinedComponent
= true;
87 error(h
, "Content must be present in a complexContent");
91 if(Content
is XmlSchemaComplexContentRestriction
)
93 XmlSchemaComplexContentRestriction xscr
= (XmlSchemaComplexContentRestriction
) Content
;
94 errorCount
+= xscr
.Compile(h
, schema
);
96 else if(Content
is XmlSchemaComplexContentExtension
)
98 XmlSchemaComplexContentExtension xsce
= (XmlSchemaComplexContentExtension
) Content
;
99 errorCount
+= xsce
.Compile(h
, schema
);
102 error(h
,"complexContent can't have any value other than restriction or extention");
105 XmlSchemaUtil
.CompileID(Id
,this, schema
.IDCollection
,h
);
107 this.CompilationId
= schema
.CompilationId
;
111 internal override int Validate(ValidationEventHandler h
, XmlSchema schema
)
113 if (IsValidated (schema
.ValidationId
))
116 errorCount
+= Content
.Validate (h
, schema
);
118 ValidationId
= schema
.ValidationId
;
124 // {any attributes with non-schema namespace . . .}>
125 // Content: (annotation?, (restriction | extension))
127 internal static XmlSchemaComplexContent
Read(XmlSchemaReader reader
, ValidationEventHandler h
)
129 XmlSchemaComplexContent complex
= new XmlSchemaComplexContent();
130 reader
.MoveToElement();
132 if(reader
.NamespaceURI
!= XmlSchema
.Namespace
|| reader
.LocalName
!= xmlname
)
134 error(h
,"Should not happen :1: XmlSchemaComplexContent.Read, name="+reader
.Name
,null);
139 complex
.LineNumber
= reader
.LineNumber
;
140 complex
.LinePosition
= reader
.LinePosition
;
141 complex
.SourceUri
= reader
.BaseURI
;
143 while(reader
.MoveToNextAttribute())
145 if(reader
.Name
== "id")
147 complex
.Id
= reader
.Value
;
149 else if(reader
.Name
== "mixed")
152 complex
.isMixed
= XmlSchemaUtil
.ReadBoolAttribute(reader
,out innerex
);
154 error(h
,reader
.Value
+ " is an invalid value for mixed",innerex
);
156 else if((reader
.NamespaceURI
== "" && reader
.Name
!= "xmlns") || reader
.NamespaceURI
== XmlSchema
.Namespace
)
158 error(h
,reader
.Name
+ " is not a valid attribute for complexContent",null);
162 XmlSchemaUtil
.ReadUnhandledAttribute(reader
,complex
);
166 reader
.MoveToElement();
167 if(reader
.IsEmptyElement
)
169 //Content: (annotation?, (restriction | extension))
171 while(reader
.ReadNextElement())
173 if(reader
.NodeType
== XmlNodeType
.EndElement
)
175 if(reader
.LocalName
!= xmlname
)
176 error(h
,"Should not happen :2: XmlSchemaComplexContent.Read, name="+reader
.Name
,null);
179 if(level
<= 1 && reader
.LocalName
== "annotation")
181 level
= 2; //Only one annotation
182 XmlSchemaAnnotation annotation
= XmlSchemaAnnotation
.Read(reader
,h
);
183 if(annotation
!= null)
184 complex
.Annotation
= annotation
;
189 if(reader
.LocalName
== "restriction")
192 XmlSchemaComplexContentRestriction restriction
= XmlSchemaComplexContentRestriction
.Read(reader
,h
);
193 if(restriction
!= null)
194 complex
.content
= restriction
;
197 if(reader
.LocalName
== "extension")
200 XmlSchemaComplexContentExtension extension
= XmlSchemaComplexContentExtension
.Read(reader
,h
);
201 if(extension
!= null)
202 complex
.content
= extension
;
206 reader
.RaiseInvalidElementError();