public override XmlSchemaSimpleType GetSimpleType(string attributeDataType) { var retVal = base.GetSimpleType(attributeDataType); var restriction = (XmlSchemaSimpleTypeRestriction) retVal.Content; var minFacet = new XmlSchemaMinInclusiveFacet { Value = TimeSpan.Zero.ToString() }; restriction.Facets.Add(minFacet); return retVal; }
public override XmlSchemaSimpleType GetSimpleType(string attributeDataType) { var retVal = base.GetSimpleType(attributeDataType); var restriction = (XmlSchemaSimpleTypeRestriction) retVal.Content; var iva = (IntegerValidatorAttribute) Attribute; var minFacet = new XmlSchemaMinInclusiveFacet { Value = iva.MinValue.ToString() }; restriction.Facets.Add(minFacet); var maxFacet = new XmlSchemaMaxInclusiveFacet { Value = iva.MaxValue.ToString() }; restriction.Facets.Add(maxFacet); return retVal; }
protected override void Visit(XmlSchemaMinInclusiveFacet facet) { AddLeaf(SimpleTypeStructureNodeType.FacetMinInclusive, facet); }
//<minInclusive // fixed = boolean : false // id = ID // value = anySimpleType // {any attributes with non-schema namespace . . .}> // Content: (annotation?) //</minInclusive> internal static XmlSchemaMinInclusiveFacet Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaMinInclusiveFacet mini = new XmlSchemaMinInclusiveFacet(); reader.MoveToElement(); if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname) { error(h,"Should not happen :1: XmlSchemaMinInclusiveFacet.Read, name="+reader.Name,null); reader.Skip(); return null; } mini.LineNumber = reader.LineNumber; mini.LinePosition = reader.LinePosition; mini.SourceUri = reader.BaseURI; while(reader.MoveToNextAttribute()) { if(reader.Name == "id") { mini.Id = reader.Value; } else if(reader.Name == "fixed") { Exception innerex; mini.IsFixed = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex); if(innerex != null) error(h, reader.Value + " is not a valid value for fixed attribute",innerex); } else if(reader.Name == "value") { mini.Value = reader.Value; } else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h,reader.Name + " is not a valid attribute for "+xmlname,null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader,mini); } } reader.MoveToElement(); if(reader.IsEmptyElement) return mini; // Content: (annotation?) int level = 1; while(reader.ReadNextElement()) { if(reader.NodeType == XmlNodeType.EndElement) { if(reader.LocalName != xmlname) error(h,"Should not happen :2: XmlSchemaMinInclusiveFacet.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) mini.Annotation = annotation; continue; } reader.RaiseInvalidElementError(); } return mini; }
protected virtual void Visit(XmlSchemaMinInclusiveFacet facet) { }
public XsdSimpleRestrictionType (RelaxngDatatype primitive, RelaxngParamList parameters) { type = new XmlSchemaSimpleType (); XmlSchemaSimpleTypeRestriction r = new XmlSchemaSimpleTypeRestriction (); type.Content = r; string ns = primitive.NamespaceURI; // Remap XML Schema datatypes namespace -> XML Schema namespace. if (ns == "http://www.w3.org/2001/XMLSchema-datatypes") ns = XSchema.Namespace; r.BaseTypeName = new XmlQualifiedName (primitive.Name, ns); foreach (RelaxngParam p in parameters) { XmlSchemaFacet f = null; string value = p.Value; switch (p.Name) { case "maxExclusive": f = new XmlSchemaMaxExclusiveFacet (); break; case "maxInclusive": f = new XmlSchemaMaxInclusiveFacet (); break; case "minExclusive": f = new XmlSchemaMinExclusiveFacet (); break; case "minInclusive": f = new XmlSchemaMinInclusiveFacet (); break; case "pattern": f = new XmlSchemaPatternFacet (); // .NET/Mono Regex has a bug that it does not support "IsLatin-1Supplement" // (it somehow breaks at '-'). value = value.Replace ("\\p{IsLatin-1Supplement}", "[\\x80-\\xFF]"); break; case "whiteSpace": f = new XmlSchemaWhiteSpaceFacet (); break; case "length": f = new XmlSchemaLengthFacet (); break; case "maxLength": f = new XmlSchemaMaxLengthFacet (); break; case "minLength": f = new XmlSchemaMinLengthFacet (); break; case "fractionDigits": f = new XmlSchemaFractionDigitsFacet (); break; case "totalDigits": f = new XmlSchemaTotalDigitsFacet (); break; default: throw new RelaxngException (String.Format ("XML Schema facet {0} is not recognized or not supported.", p.Name)); } f.Value = value; r.Facets.Add (f); } // Now we create XmlSchema to handle simple-type // based validation (since there is no other way, // because of sucky XmlSchemaSimpleType design). schema = new XSchema (); XmlSchemaElement el = new XmlSchemaElement (); el.Name = "root"; el.SchemaType = type; schema.Items.Add (el); schema.Compile (null); }
private void Write21_XmlSchemaMinInclusiveFacet(string n, string ns, XmlSchemaMinInclusiveFacet o, bool isNullable, bool needType) { if (o == null) { if (isNullable) { base.WriteNullTagLiteral(n, ns); } } else { if (!needType && !(o.GetType() == typeof(XmlSchemaMinInclusiveFacet))) { throw base.CreateUnknownTypeException(o); } base.EscapeName = false; base.WriteStartElement(n, ns, o, false, o.Namespaces); if (needType) { base.WriteXsiType("XmlSchemaMinInclusiveFacet", "http://www.w3.org/2001/XMLSchema"); } base.WriteAttribute("id", "", o.Id); XmlAttribute[] unhandledAttributes = o.UnhandledAttributes; if (unhandledAttributes != null) { for (int i = 0; i < unhandledAttributes.Length; i++) { XmlAttribute node = unhandledAttributes[i]; base.WriteXmlAttribute(node, o); } } base.WriteAttribute("value", "", o.Value); if (o.IsFixed) { base.WriteAttribute("fixed", "", XmlConvert.ToString(o.IsFixed)); } this.Write11_XmlSchemaAnnotation("annotation", "http://www.w3.org/2001/XMLSchema", o.Annotation, false, false); base.WriteEndElement(o); } }
internal static XmlSchemaMinInclusiveFacet Read(XmlSchemaReader reader, ValidationEventHandler h) { XmlSchemaMinInclusiveFacet xmlSchemaMinInclusiveFacet = new XmlSchemaMinInclusiveFacet(); reader.MoveToElement(); if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "minInclusive") { XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaMinInclusiveFacet.Read, name=" + reader.Name, null); reader.Skip(); return(null); } xmlSchemaMinInclusiveFacet.LineNumber = reader.LineNumber; xmlSchemaMinInclusiveFacet.LinePosition = reader.LinePosition; xmlSchemaMinInclusiveFacet.SourceUri = reader.BaseURI; while (reader.MoveToNextAttribute()) { if (reader.Name == "id") { xmlSchemaMinInclusiveFacet.Id = reader.Value; } else if (reader.Name == "fixed") { Exception ex; xmlSchemaMinInclusiveFacet.IsFixed = XmlSchemaUtil.ReadBoolAttribute(reader, out ex); if (ex != null) { XmlSchemaObject.error(h, reader.Value + " is not a valid value for fixed attribute", ex); } } else if (reader.Name == "value") { xmlSchemaMinInclusiveFacet.Value = reader.Value; } else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema") { XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for minInclusive", null); } else { XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaMinInclusiveFacet); } } reader.MoveToElement(); if (reader.IsEmptyElement) { return(xmlSchemaMinInclusiveFacet); } int num = 1; while (reader.ReadNextElement()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName != "minInclusive") { XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaMinInclusiveFacet.Read, name=" + reader.Name, null); } break; } if (num <= 1 && reader.LocalName == "annotation") { num = 2; XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h); if (xmlSchemaAnnotation != null) { xmlSchemaMinInclusiveFacet.Annotation = xmlSchemaAnnotation; } } else { reader.RaiseInvalidElementError(); } } return(xmlSchemaMinInclusiveFacet); }