1 // Author: Dwivedi, Ajay kumar
\r
4 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// Summary description for XmlSchemaSequence.
\r
12 public class XmlSchemaSequence : XmlSchemaGroupBase
\r
14 private XmlSchemaObjectCollection items;
\r
15 private static string xmlname = "sequence";
\r
17 public XmlSchemaSequence()
\r
19 items = new XmlSchemaObjectCollection();
\r
22 [XmlElement("element",typeof(XmlSchemaElement),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
23 [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
24 [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
25 [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
26 [XmlElement("any",typeof(XmlSchemaAny),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
27 public override XmlSchemaObjectCollection Items
\r
29 get{ return items; }
\r
32 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
\r
34 //FIXME: Should we reset the values
\r
35 if(MinOccurs > MaxOccurs)
\r
36 error(h,"minOccurs must be less than or equal to maxOccurs");
\r
38 XmlSchemaUtil.CompileID(Id, this, info.IDCollection, h);
\r
40 foreach(XmlSchemaObject obj in Items)
\r
42 if(obj is XmlSchemaElement)
\r
44 errorCount += ((XmlSchemaElement)obj).Compile(h,info);
\r
46 else if(obj is XmlSchemaGroupRef)
\r
48 errorCount += ((XmlSchemaGroupRef)obj).Compile(h,info);
\r
50 else if(obj is XmlSchemaChoice)
\r
52 errorCount += ((XmlSchemaChoice)obj).Compile(h,info);
\r
54 else if(obj is XmlSchemaSequence)
\r
56 errorCount += ((XmlSchemaSequence)obj).Compile(h,info);
\r
58 else if(obj is XmlSchemaAny)
\r
60 errorCount += ((XmlSchemaAny)obj).Compile(h,info);
\r
67 internal int Validate(ValidationEventHandler h)
\r
73 // maxOccurs = (nonNegativeInteger | unbounded) : 1
\r
74 // minOccurs = nonNegativeInteger : 1
\r
75 // {any attributes with non-schema namespace . . .}>
\r
76 // Content: (annotation?, (element | group | choice | sequence | any)*)
\r
78 internal static XmlSchemaSequence Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
80 XmlSchemaSequence sequence = new XmlSchemaSequence();
\r
81 reader.MoveToElement();
\r
83 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
85 error(h,"Should not happen :1: XmlSchemaSequence.Read, name="+reader.Name,null);
\r
90 sequence.LineNumber = reader.LineNumber;
\r
91 sequence.LinePosition = reader.LinePosition;
\r
92 sequence.SourceUri = reader.BaseURI;
\r
94 while(reader.MoveToNextAttribute())
\r
96 if(reader.Name == "id")
\r
98 sequence.Id = reader.Value;
\r
100 else if(reader.Name == "maxOccurs")
\r
104 sequence.MaxOccursString = reader.Value;
\r
108 error(h,reader.Value + " is an invalid value for maxOccurs",e);
\r
111 else if(reader.Name == "minOccurs")
\r
115 sequence.MinOccursString = reader.Value;
\r
119 error(h,reader.Value + " is an invalid value for minOccurs",e);
\r
122 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
124 error(h,reader.Name + " is not a valid attribute for sequence",null);
\r
128 XmlSchemaUtil.ReadUnhandledAttribute(reader,sequence);
\r
132 reader.MoveToElement();
\r
133 if(reader.IsEmptyElement)
\r
136 // Content: (annotation?, (element | group | choice | sequence | any)*)
\r
138 while(reader.ReadNextElement())
\r
140 if(reader.NodeType == XmlNodeType.EndElement)
\r
142 if(reader.LocalName != xmlname)
\r
143 error(h,"Should not happen :2: XmlSchemaSequence.Read, name="+reader.Name,null);
\r
146 if(level <= 1 && reader.LocalName == "annotation")
\r
148 level = 2; //Only one annotation
\r
149 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
150 if(annotation != null)
\r
151 sequence.Annotation = annotation;
\r
156 if(reader.LocalName == "element")
\r
159 XmlSchemaElement element = XmlSchemaElement.Read(reader,h);
\r
160 if(element != null)
\r
161 sequence.items.Add(element);
\r
164 if(reader.LocalName == "group")
\r
167 XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
\r
169 sequence.items.Add(group);
\r
172 if(reader.LocalName == "choice")
\r
175 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
177 sequence.items.Add(choice);
\r
180 if(reader.LocalName == "sequence")
\r
183 XmlSchemaSequence seq = XmlSchemaSequence.Read(reader,h);
\r
185 sequence.items.Add(seq);
\r
188 if(reader.LocalName == "any")
\r
191 XmlSchemaAny any = XmlSchemaAny.Read(reader,h);
\r
193 sequence.items.Add(any);
\r
197 reader.RaiseInvalidElementError();
\r