1 // Author: Dwivedi, Ajay kumar
\r
5 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// Summary description for XmlSchemaAll.
\r
12 public class XmlSchemaAll : XmlSchemaGroupBase
\r
14 private XmlSchemaObjectCollection items;
\r
15 private static string xmlname = "all";
\r
17 public XmlSchemaAll()
\r
19 items = new XmlSchemaObjectCollection();
\r
22 [XmlElement("element",typeof(XmlSchemaElement),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
23 public override XmlSchemaObjectCollection Items
\r
25 get{ return items; }
\r
29 /// 1. MaxOccurs must be one. (default is also one)
\r
30 /// 2. MinOccurs must be zero or one.
\r
33 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
\r
35 //FIXME: Should we reset the values on error??
\r
36 if(MaxOccurs != Decimal.One)
\r
37 error(h,"maxOccurs must be 1");
\r
38 if(MinOccurs != Decimal.One && MinOccurs != Decimal.Zero)
\r
39 error(h,"minOccurs must be 0 or 1");
\r
41 XmlSchemaUtil.CompileID(Id, this, info.IDCollection, h);
\r
43 foreach(XmlSchemaObject obj in Items)
\r
45 if(obj is XmlSchemaElement)
\r
47 XmlSchemaElement elem = (XmlSchemaElement)obj;
\r
48 if(elem.MaxOccurs != Decimal.One && elem.MaxOccurs != Decimal.Zero)
\r
50 elem.error(h,"The {max occurs} of all the elements of 'all' must be 0 or 1. ");
\r
52 errorCount += elem.Compile(h,info);
\r
56 error(h,"XmlSchemaAll can only contain Items of type Element");
\r
64 internal int Validate(ValidationEventHandler h)
\r
70 // maxOccurs = 1 : 1
\r
71 // minOccurs = (0 | 1) : 1
\r
72 // {any attributes with non-schema namespace . . .}>
\r
73 // Content: (annotation?, element*)
\r
75 internal static XmlSchemaAll Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
77 XmlSchemaAll all = new XmlSchemaAll();
\r
78 reader.MoveToElement();
\r
80 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
82 error(h,"Should not happen :1: XmlSchemaAll.Read, name="+reader.Name,null);
\r
87 all.LineNumber = reader.LineNumber;
\r
88 all.LinePosition = reader.LinePosition;
\r
89 all.SourceUri = reader.BaseURI;
\r
92 while(reader.MoveToNextAttribute())
\r
94 if(reader.Name == "id")
\r
96 all.Id = reader.Value;
\r
98 else if(reader.Name == "maxOccurs")
\r
102 all.MaxOccursString = reader.Value;
\r
106 error(h,reader.Value + " is an invalid value for maxOccurs",e);
\r
109 else if(reader.Name == "minOccurs")
\r
113 all.MinOccursString = reader.Value;
\r
117 error(h,reader.Value + " is an invalid value for minOccurs",e);
\r
120 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
122 error(h,reader.Name + " is not a valid attribute for all",null);
\r
126 XmlSchemaUtil.ReadUnhandledAttribute(reader,all);
\r
130 reader.MoveToElement();
\r
131 if(reader.IsEmptyElement)
\r
134 //Content: (annotation?, element*)
\r
136 while(reader.ReadNextElement())
\r
138 if(reader.NodeType == XmlNodeType.EndElement)
\r
140 if(reader.LocalName != xmlname)
\r
141 error(h,"Should not happen :2: XmlSchemaAll.Read, name="+reader.Name,null);
\r
144 if(level <= 1 && reader.LocalName == "annotation")
\r
146 level = 2; //Only one annotation
\r
147 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
148 if(annotation != null)
\r
149 all.Annotation = annotation;
\r
152 if(level <=2 && reader.LocalName == "element")
\r
155 XmlSchemaElement element = XmlSchemaElement.Read(reader,h);
\r
156 if(element != null)
\r
157 all.items.Add(element);
\r
160 reader.RaiseInvalidElementError();
\r