1 // Author: Dwivedi, Ajay kumar
\r
6 namespace System.Xml.Schema
\r
9 /// Summary description for XmlSchemaUnique.
\r
11 public class XmlSchemaUnique : XmlSchemaIdentityConstraint
\r
13 const string xmlname = "unique";
\r
15 public XmlSchemaUnique()
\r
19 /// 1. name must be present
\r
20 /// 2. selector and field must be present
\r
22 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
24 return base.Compile(h,schema);
\r
27 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
33 internal new void error(ValidationEventHandler handle, string message)
\r
36 ValidationHandler.RaiseValidationError(handle, this, message);
\r
42 // {any attributes with non-schema namespace . . .}>
\r
43 // Content: (annotation?, (selector, field+))
\r
45 internal static XmlSchemaUnique Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
47 XmlSchemaUnique unique = new XmlSchemaUnique();
\r
48 reader.MoveToElement();
\r
50 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
52 error(h,"Should not happen :1: XmlSchemaUnique.Read, name="+reader.Name,null);
\r
57 unique.LineNumber = reader.LineNumber;
\r
58 unique.LinePosition = reader.LinePosition;
\r
59 unique.SourceUri = reader.BaseURI;
\r
61 while(reader.MoveToNextAttribute())
\r
63 if(reader.Name == "id")
\r
65 unique.Id = reader.Value;
\r
67 else if(reader.Name == "name")
\r
69 unique.Name = reader.Value;
\r
71 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
73 error(h,reader.Name + " is not a valid attribute for unique",null);
\r
77 XmlSchemaUtil.ReadUnhandledAttribute(reader,unique);
\r
81 reader.MoveToElement();
\r
82 if(reader.IsEmptyElement)
\r
85 // Content: annotation?, selector, field+
\r
87 while(reader.ReadNextElement())
\r
89 if(reader.NodeType == XmlNodeType.EndElement)
\r
91 if(reader.LocalName != xmlname)
\r
92 error(h,"Should not happen :2: XmlSchemaUnion.Read, name="+reader.Name,null);
\r
95 if(level <= 1 && reader.LocalName == "annotation")
\r
97 level = 2; //Only one annotation
\r
98 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
99 if(annotation != null)
\r
100 unique.Annotation = annotation;
\r
103 if(level <= 2 && reader.LocalName == "selector")
\r
106 XmlSchemaXPath selector = XmlSchemaXPath.Read(reader,h,"selector");
\r
107 if(selector != null)
\r
108 unique.Selector = selector;
\r
111 if(level <= 3 && reader.LocalName == "field")
\r
114 if(unique.Selector == null)
\r
115 error(h,"selector must be defined before field declarations",null);
\r
116 XmlSchemaXPath field = XmlSchemaXPath.Read(reader, h, "field");
\r
118 unique.Fields.Add(field);
\r
121 reader.RaiseInvalidElementError();
\r