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 private static string xmlname = "unique";
\r
15 public XmlSchemaUnique()
\r
19 /// 1. name must be present
\r
20 /// 2. selector and field must be present
\r
23 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
25 return base.Compile(h,schema);
\r
29 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
35 internal new void error(ValidationEventHandler handle, string message)
\r
38 ValidationHandler.RaiseValidationError(handle, this, message);
\r
44 // {any attributes with non-schema namespace . . .}>
\r
45 // Content: (annotation?, (selector, field+))
\r
47 internal static XmlSchemaUnique Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
49 XmlSchemaUnique unique = new XmlSchemaUnique();
\r
50 reader.MoveToElement();
\r
52 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
54 error(h,"Should not happen :1: XmlSchemaUnique.Read, name="+reader.Name,null);
\r
59 unique.LineNumber = reader.LineNumber;
\r
60 unique.LinePosition = reader.LinePosition;
\r
61 unique.SourceUri = reader.BaseURI;
\r
63 while(reader.MoveToNextAttribute())
\r
65 if(reader.Name == "id")
\r
67 unique.Id = reader.Value;
\r
69 else if(reader.Name == "name")
\r
71 unique.Name = reader.Value;
\r
73 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
75 error(h,reader.Name + " is not a valid attribute for unique",null);
\r
79 XmlSchemaUtil.ReadUnhandledAttribute(reader,unique);
\r
83 reader.MoveToElement();
\r
84 if(reader.IsEmptyElement)
\r
87 // Content: annotation?, selector, field+
\r
89 while(reader.ReadNextElement())
\r
91 if(reader.NodeType == XmlNodeType.EndElement)
\r
93 if(reader.LocalName != xmlname)
\r
94 error(h,"Should not happen :2: XmlSchemaUnion.Read, name="+reader.Name,null);
\r
97 if(level <= 1 && reader.LocalName == "annotation")
\r
99 level = 2; //Only one annotation
\r
100 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
101 if(annotation != null)
\r
102 unique.Annotation = annotation;
\r
105 if(level <= 2 && reader.LocalName == "selector")
\r
108 XmlSchemaXPath selector = XmlSchemaXPath.Read(reader,h,"selector");
\r
109 if(selector != null)
\r
110 unique.Selector = selector;
\r
113 if(level <= 3 && reader.LocalName == "field")
\r
116 if(unique.Selector == null)
\r
117 error(h,"selector must be defined before field declarations",null);
\r
118 XmlSchemaXPath field = XmlSchemaXPath.Read(reader,h,"field");
\r
120 unique.Fields.Add(field);
\r
123 reader.RaiseInvalidElementError();
\r