/// <summary>Initializes a new instance of the <see cref="T:System.Xml.Schema.XmlSchemaAttribute" /> class.</summary> public XmlSchemaAttribute() { this.form = XmlSchemaForm.None; this.use = XmlSchemaUse.None; this.schemaTypeName = XmlQualifiedName.Empty; this.qualifiedName = XmlQualifiedName.Empty; this.refName = XmlQualifiedName.Empty; }
public XmlSchemaAttribute() { //LAMESPEC: Docs says the default is optional. //Whereas the MS implementation has default None. form = XmlSchemaForm.None; use = XmlSchemaUse.None; schemaTypeName = XmlQualifiedName.Empty; qualifiedName = XmlQualifiedName.Empty; refName = XmlQualifiedName.Empty; }
private string Write30_XmlSchemaUse(XmlSchemaUse v) { switch (v) { case XmlSchemaUse.Optional: return("optional"); case XmlSchemaUse.Prohibited: return("prohibited"); case XmlSchemaUse.Required: return("required"); } return(null); }
string Write30_XmlSchemaUse(XmlSchemaUse v) { string s = null; switch (v) { case XmlSchemaUse.@Optional: s = @"optional"; break; case XmlSchemaUse.@Prohibited: s = @"prohibited"; break; case XmlSchemaUse.@Required: s = @"required"; break; default: break; } return(s); }
private static void WriteRequiredText(this MamlWriter writer, XmlSchemaUse use) { switch (use) { case XmlSchemaUse.None: case XmlSchemaUse.Optional: break; case XmlSchemaUse.Required: writer.WriteString("Yes"); break; default: throw ExceptionBuilder.UnhandledCaseLabel(use); } }
public static XmlSchemaUse ReadUseAttribute(XmlReader reader, out Exception innerExcpetion) { innerExcpetion = null; XmlSchemaUse result = XmlSchemaUse.None; string value = reader.Value; switch (value) { case "optional": return(XmlSchemaUse.Optional); case "prohibited": return(XmlSchemaUse.Prohibited); case "required": return(XmlSchemaUse.Required); } innerExcpetion = new Exception("only optional , prohibited or required are valid values for use"); return(result); }
void Write1_XmlSchemaAttribute(XmlSchemaAttribute o) { if ((object)o == null) { return; } WriteStartElement("attribute"); WriteAttribute(@"id", @"", ((System.String)o.@Id)); WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o); WriteAttribute(@"default", @"", ((System.String)o.@DefaultValue)); WriteAttribute(@"fixed", @"", ((System.String)o.@FixedValue)); if (o.Parent != null && !(o.Parent is XmlSchema)) { if (o.QualifiedName != null && !o.QualifiedName.IsEmpty && o.QualifiedName.Namespace != null && o.QualifiedName.Namespace.Length != 0) { WriteAttribute(@"form", @"", "qualified"); } else { WriteAttribute(@"form", @"", "unqualified"); } } WriteAttribute(@"name", @"", ((System.String)o.@Name)); if (!o.RefName.IsEmpty) { WriteAttribute("ref", "", o.RefName); } else if (!o.SchemaTypeName.IsEmpty) { WriteAttribute("type", "", o.SchemaTypeName); } XmlSchemaUse use = o.Use == XmlSchemaUse.None ? XmlSchemaUse.Optional : o.Use; WriteAttribute(@"use", @"", Write30_XmlSchemaUse(use)); Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation); Write9_XmlSchemaSimpleType((XmlSchemaSimpleType)o.@SchemaType); WriteEndElement(); }
public static XmlSchemaUse ReadUseAttribute(XmlReader reader, out Exception innerExcpetion) { innerExcpetion = null; XmlSchemaUse val = XmlSchemaUse.None; switch (reader.Value) { case "optional": val = XmlSchemaUse.Optional; break; case "prohibited": val = XmlSchemaUse.Prohibited; break; case "required": val = XmlSchemaUse.Required; break; default: innerExcpetion = new Exception("only optional , prohibited or required are valid values for use"); break; } return(val); }
private void Write1_XmlSchemaAttribute(XmlSchemaAttribute o) { if (o != null) { this.WriteStartElement("attribute"); this.WriteAttribute("id", "", o.Id); this.WriteAttributes(o.UnhandledAttributes, o); this.WriteAttribute("default", "", o.DefaultValue); this.WriteAttribute("fixed", "", o.FixedValue); if ((o.Parent != null) && !(o.Parent is XmlSchema)) { if (((o.QualifiedName != null) && !o.QualifiedName.IsEmpty) && ((o.QualifiedName.Namespace != null) && (o.QualifiedName.Namespace.Length != 0))) { this.WriteAttribute("form", "", "qualified"); } else { this.WriteAttribute("form", "", "unqualified"); } } this.WriteAttribute("name", "", o.Name); if (!o.RefName.IsEmpty) { this.WriteAttribute("ref", "", o.RefName); } else if (!o.SchemaTypeName.IsEmpty) { this.WriteAttribute("type", "", o.SchemaTypeName); } XmlSchemaUse v = (o.Use == XmlSchemaUse.None) ? XmlSchemaUse.Optional : o.Use; this.WriteAttribute("use", "", this.Write30_XmlSchemaUse(v)); this.Write5_XmlSchemaAnnotation(o.Annotation); this.Write9_XmlSchemaSimpleType(o.SchemaType); this.WriteEndElement(); } }
/// <summary> /// Constructs an XmlSchemaAttribute and initialize it with the given parameters /// </summary> /// <param name="Name">The attribute name</param> /// <param name="SchemaTypeName">Qualified name of the type for this attribute</param> /// <param name="Use">Whether the attribute is required or optional</param> /// <returns>The new attribute</returns> static XmlSchemaAttribute CreateSchemaAttribute(string Name, XmlQualifiedName SchemaTypeName, XmlSchemaUse Use) { XmlSchemaAttribute Attribute = new XmlSchemaAttribute(); Attribute.Name = Name; Attribute.SchemaTypeName = SchemaTypeName; Attribute.Use = Use; return Attribute; }
string Write30_XmlSchemaUse(XmlSchemaUse v) { string s = null; switch (v) { case XmlSchemaUse.@Optional:s = @"optional"; break; case XmlSchemaUse.@Prohibited:s = @"prohibited"; break; case XmlSchemaUse.@Required:s = @"required"; break; default: break; } return s; }
private string Write35_XmlSchemaUse(XmlSchemaUse v) { switch (v) { case XmlSchemaUse.Optional: return "optional"; case XmlSchemaUse.Prohibited: return "prohibited"; case XmlSchemaUse.Required: return "required"; } long num = (long) v; throw base.CreateInvalidEnumValueException(num.ToString(CultureInfo.InvariantCulture), "System.Xml.Schema.XmlSchemaUse"); }
internal override int Validate(ValidationEventHandler h, XmlSchema schema) { if (base.IsValidated(schema.ValidationId)) { return(this.errorCount); } if (this.SchemaType != null) { this.SchemaType.Validate(h, schema); this.attributeType = this.SchemaType; } else if (this.SchemaTypeName != null && this.SchemaTypeName != XmlQualifiedName.Empty) { XmlSchemaType xmlSchemaType = schema.FindSchemaType(this.SchemaTypeName); if (xmlSchemaType is XmlSchemaComplexType) { base.error(h, "An attribute can't have complexType Content"); } else if (xmlSchemaType != null) { this.errorCount += xmlSchemaType.Validate(h, schema); this.attributeType = xmlSchemaType; } else if (this.SchemaTypeName == XmlSchemaComplexType.AnyTypeName) { this.attributeType = XmlSchemaComplexType.AnyType; } else if (XmlSchemaUtil.IsBuiltInDatatypeName(this.SchemaTypeName)) { this.attributeType = XmlSchemaDatatype.FromName(this.SchemaTypeName); if (this.attributeType == null) { base.error(h, "Invalid xml schema namespace datatype was specified."); } } else if (!schema.IsNamespaceAbsent(this.SchemaTypeName.Namespace)) { base.error(h, "Referenced schema type " + this.SchemaTypeName + " was not found in the corresponding schema."); } } if (this.RefName != null && this.RefName != XmlQualifiedName.Empty) { this.referencedAttribute = schema.FindAttribute(this.RefName); if (this.referencedAttribute != null) { this.errorCount += this.referencedAttribute.Validate(h, schema); } else if (!schema.IsNamespaceAbsent(this.RefName.Namespace)) { base.error(h, "Referenced attribute " + this.RefName + " was not found in the corresponding schema."); } } if (this.attributeType == null) { this.attributeType = XmlSchemaSimpleType.AnySimpleType; } if (this.defaultValue != null || this.fixedValue != null) { XmlSchemaDatatype xmlSchemaDatatype = this.attributeType as XmlSchemaDatatype; if (xmlSchemaDatatype == null) { xmlSchemaDatatype = ((XmlSchemaSimpleType)this.attributeType).Datatype; } if (xmlSchemaDatatype.TokenizedType == XmlTokenizedType.QName) { base.error(h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values."); } else { try { if (this.defaultValue != null) { this.validatedDefaultValue = xmlSchemaDatatype.Normalize(this.defaultValue); xmlSchemaDatatype.ParseValue(this.validatedDefaultValue, null, null); } } catch (Exception innerException) { XmlSchemaObject.error(h, "The Attribute's default value is invalid with its type definition.", innerException); } try { if (this.fixedValue != null) { this.validatedFixedValue = xmlSchemaDatatype.Normalize(this.fixedValue); this.validatedFixedTypedValue = xmlSchemaDatatype.ParseValue(this.validatedFixedValue, null, null); } } catch (Exception innerException2) { XmlSchemaObject.error(h, "The Attribute's fixed value is invalid with its type definition.", innerException2); } } } if (this.Use == XmlSchemaUse.None) { this.validatedUse = XmlSchemaUse.Optional; } else { this.validatedUse = this.Use; } if (this.attributeType != null) { this.attributeSchemaType = (this.attributeType as XmlSchemaSimpleType); if (this.attributeType == XmlSchemaSimpleType.AnySimpleType) { this.attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType; } if (this.attributeSchemaType == null) { this.attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType(this.SchemaTypeName); } } this.ValidationId = schema.ValidationId; return(this.errorCount); }
/// <summary> /// Constructs an XmlSchemaAttribute and initialize it with the given parameters /// </summary> /// <param name="Name">The attribute name</param> /// <param name="SchemaTypeName">Qualified name of the type for this attribute</param> /// <param name="Use">Whether the attribute is required or optional</param> /// <returns>The new attribute</returns> static XmlSchemaAttribute CreateSchemaAttribute(string Name, XmlQualifiedName SchemaTypeName, XmlSchemaUse Use) { XmlSchemaAttribute Attribute = new XmlSchemaAttribute(); Attribute.Name = Name; Attribute.SchemaTypeName = SchemaTypeName; Attribute.Use = Use; return(Attribute); }
/// <summary> /// Constructs an XmlSchemaAttribute and initialize it with the given parameters /// </summary> /// <param name="Name">The attribute name</param> /// <param name="SchemaType">Type enumeration for the attribute</param> /// <param name="Use">Whether the attribute is required or optional</param> /// <returns>A new XmlSchemaAttribute object</returns> static XmlSchemaAttribute CreateSchemaAttribute(string Name, ScriptSchemaStandardType SchemaType, XmlSchemaUse Use) { return(CreateSchemaAttribute(Name, GetQualifiedTypeName(SchemaType), Use)); }
/// <summary> /// Schema Component: /// QName, SimpleType, Scope, Default|Fixed, annotation /// </summary> internal override int Validate(ValidationEventHandler h, XmlSchema schema) { if (IsValidated(schema.ValidationId)) { return(errorCount); } // -- Attribute Declaration Schema Component -- // {name}, {target namespace} -> QualifiedName. Already Compile()d. // {type definition} -> attributeType. From SchemaType or SchemaTypeName. // {scope} -> ParentIsSchema | isRedefineChild. // {value constraint} -> ValidatedFixedValue, ValidatedDefaultValue. // {annotation} // -- Attribute Use Schema Component -- // {required} // {attribute declaration} // {value constraint} // First, fill type information for type reference if (SchemaType != null) { SchemaType.Validate(h, schema); attributeType = SchemaType; } else if (SchemaTypeName != null && SchemaTypeName != XmlQualifiedName.Empty) { // If type is null, then it is missing sub components . XmlSchemaType type = schema.FindSchemaType(SchemaTypeName); if (type is XmlSchemaComplexType) { error(h, "An attribute can't have complexType Content"); } else if (type != null) // simple type { errorCount += type.Validate(h, schema); attributeType = type; } else if (SchemaTypeName == XmlSchemaComplexType.AnyTypeName) { attributeType = XmlSchemaComplexType.AnyType; } else if (XmlSchemaUtil.IsBuiltInDatatypeName(SchemaTypeName)) { attributeType = XmlSchemaDatatype.FromName(SchemaTypeName); if (attributeType == null) { error(h, "Invalid xml schema namespace datatype was specified."); } } // otherwise, it might be missing sub components. else if (!schema.IsNamespaceAbsent(SchemaTypeName.Namespace)) { error(h, "Referenced schema type " + SchemaTypeName + " was not found in the corresponding schema."); } } // Then, fill type information for the type references for the referencing attributes if (RefName != null && RefName != XmlQualifiedName.Empty) { referencedAttribute = schema.FindAttribute(RefName); // If el is null, then it is missing sub components . if (referencedAttribute != null) { errorCount += referencedAttribute.Validate(h, schema); } // otherwise, it might be missing sub components. else if (!schema.IsNamespaceAbsent(RefName.Namespace)) { error(h, "Referenced attribute " + RefName + " was not found in the corresponding schema."); } } if (attributeType == null) { attributeType = XmlSchemaSimpleType.AnySimpleType; } // Validate {value constraints} if (defaultValue != null || fixedValue != null) { XmlSchemaDatatype datatype = attributeType as XmlSchemaDatatype; if (datatype == null) { datatype = ((XmlSchemaSimpleType)attributeType).Datatype; } if (datatype.TokenizedType == XmlTokenizedType.QName) { error(h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values."); } else { try { if (defaultValue != null) { validatedDefaultValue = datatype.Normalize(defaultValue); datatype.ParseValue(validatedDefaultValue, null, null); } } catch (Exception ex) { // FIXME: This is not a good way to handle exception. error(h, "The Attribute's default value is invalid with its type definition.", ex); } try { if (fixedValue != null) { validatedFixedValue = datatype.Normalize(fixedValue); validatedFixedTypedValue = datatype.ParseValue(validatedFixedValue, null, null); } } catch (Exception ex) { // FIXME: This is not a good way to handle exception. error(h, "The Attribute's fixed value is invalid with its type definition.", ex); } } } if (Use == XmlSchemaUse.None) { validatedUse = XmlSchemaUse.Optional; } else { validatedUse = Use; } #if NET_2_0 if (attributeType != null) { attributeSchemaType = attributeType as XmlSchemaSimpleType; if (attributeType == XmlSchemaSimpleType.AnySimpleType) { attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType; } if (attributeSchemaType == null) { attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType(SchemaTypeName); } } #endif ValidationId = schema.ValidationId; return(errorCount); }
/// <summary> /// Constructs an XmlSchemaAttribute and initialize it with the given parameters /// </summary> /// <param name="Name">The attribute name</param> /// <param name="SchemaType">Type enumeration for the attribute</param> /// <param name="Use">Whether the attribute is required or optional</param> /// <returns>A new XmlSchemaAttribute object</returns> static XmlSchemaAttribute CreateSchemaAttribute(string Name, ScriptSchemaStandardType SchemaType, XmlSchemaUse Use) { return CreateSchemaAttribute(Name, GetQualifiedTypeName(SchemaType), Use); }
protected override bool Validate() { string controlValue = ControlToValidate.Text.Trim(); bool valid = true; if (IsEnabled && ControlToValidate.Enabled) { String minInclusive = null; String minExclusive = null; String maxInclusive = null; String maxExclusive = null; String length = null; String minLength = null; String maxLength = null; var errorMessage = new StringBuilder(); XmlSchemaAttribute attribute = null; SchemaManager.FindAttribute(_targetNamespace, _typeName, _attributeName, out attribute); if (attribute == null) { LogManager.Error("XSDSchemaValidator - Failed to locate attribute: {0} in {1}", _attributeName, _targetNamespace); } else { XmlSchemaUse use = attribute.Use; XmlSchemaSimpleType attributeSchemaType = attribute.AttributeSchemaType; XmlQualifiedName qname = attributeSchemaType.BaseXmlSchemaType.QualifiedName; String typeName = qname.Name; ErrorProvider.SetError(_controlToValidate, ""); if (attributeSchemaType.Content is XmlSchemaSimpleTypeRestriction) { var restr = (XmlSchemaSimpleTypeRestriction)attributeSchemaType.Content; foreach (object facet in restr.Facets) { if (facet is XmlSchemaMinInclusiveFacet) { var lf = facet as XmlSchemaMinInclusiveFacet; if (!String.IsNullOrEmpty(controlValue)) { int iResult; double dResult; if ((typeName.Contains("int") && int.TryParse(controlValue, out iResult) && iResult < int.Parse(lf.Value)) || (typeName.Contains("dou") && double.TryParse(controlValue, out dResult) && dResult < double.Parse(lf.Value))) { errorMessage.Append((errorMessage.Length > 0) ? "\r\n" : "") .Append(String.Format("The value must not be less than {0}", lf.Value)); } } } else if (facet is XmlSchemaMinExclusiveFacet) { minExclusive = ((XmlSchemaMinExclusiveFacet)facet).Value; } else if (facet is XmlSchemaMaxInclusiveFacet) { maxInclusive = ((XmlSchemaMaxInclusiveFacet)facet).Value; } else if (facet is XmlSchemaMaxExclusiveFacet) { maxExclusive = ((XmlSchemaMaxExclusiveFacet)facet).Value; } else if (facet is XmlSchemaLengthFacet) { var lf = facet as XmlSchemaLengthFacet; if (!String.IsNullOrEmpty(controlValue) && controlValue.Length > int.Parse(lf.Value)) { errorMessage.Append((errorMessage.Length > 0) ? "\r\n" : "") .Append(String.Format("The value's length must not excede {0} characters", lf.Value)); } } else if (facet is XmlSchemaMinLengthFacet) { var lf = facet as XmlSchemaMinLengthFacet; if (!String.IsNullOrEmpty(controlValue) && controlValue.Length < int.Parse(lf.Value)) { errorMessage.Append((errorMessage.Length > 0) ? "\r\n" : "") .Append(String.Format("The value's length must not be less than {0} characters", lf.Value)); } } else if (facet is XmlSchemaMaxLengthFacet) { var lf = facet as XmlSchemaMaxLengthFacet; if (!String.IsNullOrEmpty(controlValue) && controlValue.Length > int.Parse(lf.Value)) { errorMessage.Append((errorMessage.Length > 0) ? "\r\n" : "") .Append( String.Format("The value's length must not be greater than {0} characters", lf.Value)); } } else if (facet is XmlSchemaPatternFacet) { var spf = facet as XmlSchemaPatternFacet; //Console.WriteLine(spf.Id + " : " + spf.Value); if (!Regex.IsMatch(controlValue, spf.Value)) { if (_icon != null) { ErrorProvider.Icon = _icon; } errorMessage.Append((errorMessage.Length > 0) ? "\r\n" : "") .Append(String.Format( "The \"{0}\" value must match the regular expression: {1}", _attributeName, spf.Value)); valid = false; } } else if (facet is XmlSchemaEnumerationFacet) { } else if (facet is XmlSchemaTotalDigitsFacet) { } else if (facet is XmlSchemaWhiteSpaceFacet) { } } ErrorProvider.SetError(_controlToValidate, errorMessage.ToString()); } } } if (!valid) { if (ControlToValidate is ATMLControl) { ((ATMLControl)ControlToValidate).HasErrors = true; } } return(valid); }
/// <summary> /// Schema Component: /// QName, SimpleType, Scope, Default|Fixed, annotation /// </summary> internal override int Validate(ValidationEventHandler h, XmlSchema schema) { if(IsValidated (schema.ValidationId)) return errorCount; // -- Attribute Declaration Schema Component -- // {name}, {target namespace} -> QualifiedName. Already Compile()d. // {type definition} -> attributeType. From SchemaType or SchemaTypeName. // {scope} -> ParentIsSchema | isRedefineChild. // {value constraint} -> ValidatedFixedValue, ValidatedDefaultValue. // {annotation} // -- Attribute Use Schema Component -- // {required} // {attribute declaration} // {value constraint} // First, fill type information for type reference if (SchemaType != null) { SchemaType.Validate (h, schema); attributeType = SchemaType; } else if (SchemaTypeName != null && SchemaTypeName != XmlQualifiedName.Empty) { // If type is null, then it is missing sub components . XmlSchemaType type = schema.FindSchemaType (SchemaTypeName); if (type is XmlSchemaComplexType) error(h,"An attribute can't have complexType Content"); else if (type != null) { // simple type errorCount += type.Validate (h, schema); attributeType = type; } else if (SchemaTypeName == XmlSchemaComplexType.AnyTypeName) attributeType = XmlSchemaComplexType.AnyType; else if (XmlSchemaUtil.IsBuiltInDatatypeName (SchemaTypeName)) { attributeType = XmlSchemaDatatype.FromName (SchemaTypeName); if (attributeType == null) error (h, "Invalid xml schema namespace datatype was specified."); } // otherwise, it might be missing sub components. else if (!schema.IsNamespaceAbsent (SchemaTypeName.Namespace)) error (h, "Referenced schema type " + SchemaTypeName + " was not found in the corresponding schema."); } // Then, fill type information for the type references for the referencing attributes if (RefName != null && RefName != XmlQualifiedName.Empty) { referencedAttribute = schema.FindAttribute (RefName); // If el is null, then it is missing sub components . if (referencedAttribute != null) errorCount += referencedAttribute.Validate (h, schema); // otherwise, it might be missing sub components. else if (!schema.IsNamespaceAbsent (RefName.Namespace)) error (h, "Referenced attribute " + RefName + " was not found in the corresponding schema."); } if (attributeType == null) attributeType = XmlSchemaSimpleType.AnySimpleType; // Validate {value constraints} if (defaultValue != null || fixedValue != null) { XmlSchemaDatatype datatype = attributeType as XmlSchemaDatatype; if (datatype == null) datatype = ((XmlSchemaSimpleType) attributeType).Datatype; if (datatype.TokenizedType == XmlTokenizedType.QName) error (h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values."); else { try { if (defaultValue != null) { validatedDefaultValue = datatype.Normalize (defaultValue); datatype.ParseValue (validatedDefaultValue, null, null); } } catch (Exception ex) { // FIXME: This is not a good way to handle exception. error (h, "The Attribute's default value is invalid with its type definition.", ex); } try { if (fixedValue != null) { validatedFixedValue = datatype.Normalize (fixedValue); validatedFixedTypedValue = datatype.ParseValue (validatedFixedValue, null, null); } } catch (Exception ex) { // FIXME: This is not a good way to handle exception. error (h, "The Attribute's fixed value is invalid with its type definition.", ex); } } } if (Use == XmlSchemaUse.None) validatedUse = XmlSchemaUse.Optional; else validatedUse = Use; #if NET_2_0 if (attributeType != null) { attributeSchemaType = attributeType as XmlSchemaSimpleType; if (attributeType == XmlSchemaSimpleType.AnySimpleType) attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType; if (attributeSchemaType == null) attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType (SchemaTypeName); } #endif ValidationId = schema.ValidationId; return errorCount; }
private string Write30_XmlSchemaUse(XmlSchemaUse v) { switch (v) { case XmlSchemaUse.Optional: return "optional"; case XmlSchemaUse.Prohibited: return "prohibited"; case XmlSchemaUse.Required: return "required"; } return null; }