1 // Author: Dwivedi, Ajay kumar
\r
4 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// refers to the named group
\r
12 public class XmlSchemaGroup : XmlSchemaAnnotated
\r
14 private string name;
\r
15 private XmlSchemaGroupBase particle;
\r
16 private XmlQualifiedName qualifiedName;
\r
18 private static string xmlname = "group";
\r
20 public XmlSchemaGroup()
\r
24 [System.Xml.Serialization.XmlAttribute("name")]
\r
27 get{ return name; }
\r
28 set{ name = value; }
\r
31 [XmlElement("all",typeof(XmlSchemaAll),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
32 [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
33 [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
34 public XmlSchemaGroupBase Particle
\r
36 get{ return particle; }
\r
37 set{ particle = value; }
\r
41 internal XmlQualifiedName QualifiedName
\r
43 get{ return qualifiedName;}
\r
46 // 1. name must be present
\r
47 // 2. MinOccurs & MaxOccurs of the Particle must be absent
\r
49 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
\r
52 error(h,"Required attribute name must be present");
\r
53 else if(!XmlSchemaUtil.CheckNCName(this.name))
\r
54 error(h,"attribute name must be NCName");
\r
56 qualifiedName = new XmlQualifiedName(Name,info.TargetNamespace);
\r
58 if(Particle == null)
\r
60 error(h,"Particle is required");
\r
64 if(Particle.MaxOccursString != null)
\r
65 Particle.error(h,"MaxOccurs must not be present when the Particle is a child of Group");
\r
66 if(Particle.MinOccursString != null)
\r
67 Particle.error(h,"MinOccurs must not be present when the Particle is a child of Group");
\r
69 if(Particle is XmlSchemaChoice)
\r
71 errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);
\r
73 else if(Particle is XmlSchemaSequence)
\r
75 errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);
\r
77 else if(Particle is XmlSchemaAll)
\r
79 errorCount += ((XmlSchemaAll)Particle).Compile(h,info);
\r
83 error(h,"only all,choice or sequence are allowed");
\r
87 XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
\r
93 internal int Validate(ValidationEventHandler h)
\r
102 // {any attributes with non-schema namespace . . .}>
\r
103 // Content: (annotation?, (all | choice | sequence)?)
\r
105 internal static XmlSchemaGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
107 XmlSchemaGroup group = new XmlSchemaGroup();
\r
108 reader.MoveToElement();
\r
110 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
112 error(h,"Should not happen :1: XmlSchemaGroup.Read, name="+reader.Name,null);
\r
117 group.LineNumber = reader.LineNumber;
\r
118 group.LinePosition = reader.LinePosition;
\r
119 group.SourceUri = reader.BaseURI;
\r
121 while(reader.MoveToNextAttribute())
\r
123 if(reader.Name == "id")
\r
125 group.Id = reader.Value;
\r
127 else if(reader.Name == "name")
\r
129 group.name = reader.Value;
\r
131 else if(reader.NamespaceURI == "" || reader.NamespaceURI == XmlSchema.Namespace)
\r
133 error(h,reader.Name + " is not a valid attribute for group",null);
\r
137 if(reader.Prefix == "xmlns")
\r
138 group.Namespaces.Add(reader.LocalName, reader.Value);
\r
139 else if(reader.Name == "xmlns")
\r
140 group.Namespaces.Add("",reader.Value);
\r
141 //TODO: Add to Unhandled attributes
\r
145 reader.MoveToElement();
\r
146 if(reader.IsEmptyElement)
\r
149 // Content: (annotation?, (all | choice | sequence)?)
\r
151 while(reader.ReadNextElement())
\r
153 if(reader.NodeType == XmlNodeType.EndElement)
\r
155 if(reader.LocalName != xmlname)
\r
156 error(h,"Should not happen :2: XmlSchemaGroup.Read, name="+reader.Name,null);
\r
159 if(level <= 1 && reader.LocalName == "annotation")
\r
161 level = 2; //Only one annotation
\r
162 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
163 if(annotation != null)
\r
164 group.Annotation = annotation;
\r
169 if(reader.LocalName == "all")
\r
172 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
174 group.Particle = all;
\r
177 if(reader.LocalName == "choice")
\r
180 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
182 group.Particle = choice;
\r
185 if(reader.LocalName == "sequence")
\r
188 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
189 if(sequence != null)
\r
190 group.Particle = sequence;
\r
194 reader.RaiseInvalidElementError();
\r