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
48 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
\r
51 error(h,"Required attribute name must be present");
\r
52 else if(!XmlSchemaUtil.CheckNCName(this.name))
\r
53 error(h,"attribute name must be NCName");
\r
55 qualifiedName = new XmlQualifiedName(Name,info.targetNS);
\r
57 if(Particle == null)
\r
59 error(h,"Particle is required");
\r
61 else if(Particle is XmlSchemaChoice)
\r
63 errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);
\r
65 else if(Particle is XmlSchemaSequence)
\r
67 errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);
\r
69 else if(Particle is XmlSchemaAll)
\r
71 errorCount += ((XmlSchemaAll)Particle).Compile(h,info);
\r
75 error(h,"only all,choice or sequence are allowed");
\r
78 if(this.Id != null && !XmlSchemaUtil.CheckID(Id))
\r
79 error(h, "id must be a valid ID");
\r
85 internal int Validate(ValidationEventHandler h)
\r
94 // {any attributes with non-schema namespace . . .}>
\r
95 // Content: (annotation?, (all | choice | sequence)?)
\r
97 internal static XmlSchemaGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
99 XmlSchemaGroup group = new XmlSchemaGroup();
\r
100 reader.MoveToElement();
\r
102 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
104 error(h,"Should not happen :1: XmlSchemaGroup.Read, name="+reader.Name,null);
\r
109 group.LineNumber = reader.LineNumber;
\r
110 group.LinePosition = reader.LinePosition;
\r
111 group.SourceUri = reader.BaseURI;
\r
113 while(reader.MoveToNextAttribute())
\r
115 if(reader.Name == "id")
\r
117 group.Id = reader.Value;
\r
119 else if(reader.Name == "name")
\r
121 group.name = reader.Value;
\r
123 else if(reader.NamespaceURI == "" || reader.NamespaceURI == XmlSchema.Namespace)
\r
125 error(h,reader.Name + " is not a valid attribute for group",null);
\r
129 //TODO: Add to Unhandled attributes
\r
133 reader.MoveToElement();
\r
134 if(reader.IsEmptyElement)
\r
137 // Content: (annotation?, (all | choice | sequence)?)
\r
139 while(reader.ReadNextElement())
\r
141 if(reader.NodeType == XmlNodeType.EndElement)
\r
143 if(reader.LocalName != xmlname)
\r
144 error(h,"Should not happen :2: XmlSchemaGroup.Read, name="+reader.Name,null);
\r
147 if(level <= 1 && reader.LocalName == "annotation")
\r
149 level = 2; //Only one annotation
\r
150 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
151 if(annotation != null)
\r
152 group.Annotation = annotation;
\r
157 if(reader.LocalName == "all")
\r
160 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
162 group.Particle = all;
\r
165 if(reader.LocalName == "choice")
\r
168 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
170 group.Particle = choice;
\r
173 if(reader.LocalName == "sequence")
\r
176 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
177 if(sequence != null)
\r
178 group.Particle = sequence;
\r
182 reader.RaiseInvalidElementError();
\r