/* * internal new void error(ValidationEventHandler handle, string message) * { * errorCount++; * ValidationHandler.RaiseValidationError(handle, this, message); * } */ //<unique // id = ID // name = NCName // {any attributes with non-schema namespace . . .}> // Content: (annotation?, (selector, field+)) //</unique> internal static XmlSchemaUnique Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaUnique unique = new XmlSchemaUnique(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h, "Should not happen :1: XmlSchemaUnique.Read, name=" + reader.Name, null); reader.Skip(); return(null); } unique.LineNumber = reader.LineNumber; unique.LinePosition = reader.LinePosition; unique.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { unique.Id = reader.Value; } else if (reader.Name == "name") { unique.Name = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for unique", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, unique); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(unique); } // Content: annotation?, selector, field+ int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != xmlname) { error(h, "Should not happen :2: XmlSchemaUnion.Read, name=" + reader.Name, null); } break; } if (level <= 1 && reader.LocalName == "annotation") { level = 2; //Only one annotation XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { unique.Annotation = annotation; } continue; } if (level <= 2 && reader.LocalName == "selector") { level = 3; XmlSchemaXPath selector = XmlSchemaXPath.Read(reader, h, "selector"); if (selector != null) { unique.Selector = selector; } continue; } if (level <= 3 && reader.LocalName == "field") { level = 3; if (unique.Selector == null) { error(h, "selector must be defined before field declarations", null); } XmlSchemaXPath field = XmlSchemaXPath.Read(reader, h, "field"); if (field != null) { unique.Fields.Add(field); } continue; } reader.RaiseInvalidElementError(); } return(unique); }
/// <remarks> /// 1. name must be present /// 2. selector and field must be present /// </remarks> internal override int Compile(ValidationEventHandler h, XmlSchema schema) { // If this is already compiled this time, simply skip. if (CompilationId == schema.CompilationId) { return(0); } if (Name == null) { error(h, "Required attribute name must be present"); } else if (!XmlSchemaUtil.CheckNCName(this.name)) { error(h, "attribute name must be NCName"); } else { this.qName = new XmlQualifiedName(Name, AncestorSchema.TargetNamespace); if (schema.NamedIdentities.Contains(qName)) { XmlSchemaIdentityConstraint existing = schema.NamedIdentities [qName] as XmlSchemaIdentityConstraint; error(h, String.Format("There is already same named identity constraint in this namespace. Existing item is at {0}({1},{2})", existing.SourceUri, existing.LineNumber, existing.LinePosition)); } else { schema.NamedIdentities.Add(qName, this); } } if (Selector == null) { error(h, "selector must be present"); } else { Selector.isSelector = true; errorCount += Selector.Compile(h, schema); if (selector.errorCount == 0) { compiledSelector = new XsdIdentitySelector(Selector); } } if (errorCount > 0) { return(errorCount); // fatal } if (Fields.Count == 0) { error(h, "atleast one field value must be present"); } else { for (int i = 0; i < Fields.Count; i++) { XmlSchemaXPath field = Fields [i] as XmlSchemaXPath; if (field != null) { errorCount += field.Compile(h, schema); if (field.errorCount == 0) { this.compiledSelector.AddField(new XsdIdentityField(field, i)); } } else { error(h, "Object of type " + Fields [i].GetType() + " is invalid in the Fields Collection"); } } } XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h); this.CompilationId = schema.CompilationId; return(errorCount); }
//<selector // id = ID // xpath = a subset of XPath expression, see below // {any attributes with non-schema namespace . . .}> // Content: (annotation?) //</selector> internal static XmlSchemaXPath Read(XmlSchemaReader reader, ValidationEventHandler h, string name) { XmlSchemaXPath path = new XmlSchemaXPath(); reader.MoveToElement(); if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != name) { error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null); reader.Skip(); return(null); } path.LineNumber = reader.LineNumber; path.LinePosition = reader.LinePosition; path.SourceUri = reader.BaseURI; XmlNamespaceManager currentMgr = XmlSchemaUtil.GetParserContext(reader.Reader).NamespaceManager; if (currentMgr != null) { path.nsmgr = new XmlNamespaceManager(reader.NameTable); IEnumerator e = currentMgr.GetEnumerator(); while (e.MoveNext()) { string prefix = e.Current as string; switch (prefix) { case "xml": case "xmlns": continue; default: path.nsmgr.AddNamespace(prefix, currentMgr.LookupNamespace(prefix, false)); break; } } } while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { path.Id = reader.Value; } else if (reader.Name == "xpath") { path.xpath = reader.Value; } else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h, reader.Name + " is not a valid attribute for " + name, null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, path); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(path); } // Content: (annotation?) int level = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != name) { error(h, "Should not happen :2: XmlSchemaXPath.Read, name=" + reader.Name, null); } break; } if (level <= 1 && reader.LocalName == "annotation") { level = 2; //Only one annotation XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h); if (annotation != null) { path.Annotation = annotation; } continue; } reader.RaiseInvalidElementError(); } return(path); }