internal XSFractionDigitsFacet(XmlSchemaFractionDigitsFacet fractionDigitsFacet) { _facet = fractionDigitsFacet; if (_facet.Annotation is XmlSchemaAnnotation annotation) { _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation); _annotation.BindToContainer(RootContainer, this); } }
public static IEnumerable <XmlSchemaFacet> createXmlFacets(IEnumerable <ICctsFacet> facets) { var xmlFacets = new List <XmlSchemaFacet>(); foreach (var facet in facets) { XmlSchemaFacet xmlFacet = null; switch (facet.name) { case "fractionDigit": xmlFacet = new XmlSchemaFractionDigitsFacet(); break; case "length": xmlFacet = new XmlSchemaLengthFacet(); break; case "maxExclusive": xmlFacet = new XmlSchemaMaxExclusiveFacet(); break; case "maxInclusive": xmlFacet = new XmlSchemaMaxInclusiveFacet(); break; case "maxLength": xmlFacet = new XmlSchemaMaxLengthFacet(); break; case "minExclusive": xmlFacet = new XmlSchemaMinExclusiveFacet(); break; case "minInclusive": xmlFacet = new XmlSchemaMinInclusiveFacet(); break; case "minLength": xmlFacet = new XmlSchemaMinLengthFacet(); break; case "pattern": xmlFacet = new XmlSchemaPatternFacet(); break; case "totalDigits": xmlFacet = new XmlSchemaTotalDigitsFacet(); break; case "whiteSpace": xmlFacet = new XmlSchemaWhiteSpaceFacet(); break; case "enumeration": foreach (var enumValue in facet.content.Split('|')) { var enumerationFacet = new XmlSchemaEnumerationFacet(); enumerationFacet.Value = enumValue; xmlFacets.Add(enumerationFacet); } break; } if (xmlFacet != null) { xmlFacet.Value = facet.content; xmlFacets.Add(xmlFacet); } } return(xmlFacets); }
protected override void Visit(XmlSchemaFractionDigitsFacet facet) { AddLeaf(SimpleTypeStructureNodeType.FacetFractionDigits, facet); }
public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:simpleType name="RatingType"> XmlSchemaSimpleType RatingType = new XmlSchemaSimpleType(); RatingType.Name = "RatingType"; // <xs:restriction base="xs:number"> XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction(); restriction.BaseTypeName = new XmlQualifiedName("decimal", "http://www.w3.org/2001/XMLSchema"); // <xs:totalDigits value="2"/> XmlSchemaTotalDigitsFacet totalDigits = new XmlSchemaTotalDigitsFacet(); totalDigits.Value = "2"; restriction.Facets.Add(totalDigits); // <xs:fractionDigits value="1"/> XmlSchemaFractionDigitsFacet fractionDigits = new XmlSchemaFractionDigitsFacet(); fractionDigits.Value = "1"; restriction.Facets.Add(fractionDigits); RatingType.Content = restriction; schema.Items.Add(RatingType); // <xs:element name="movie"> XmlSchemaElement element = new XmlSchemaElement(); element.Name = "movie"; // <xs:complexType> XmlSchemaComplexType complexType = new XmlSchemaComplexType(); // <xs:attribute name="rating" type="RatingType"/> XmlSchemaAttribute ratingAttribute = new XmlSchemaAttribute(); ratingAttribute.Name = "rating"; ratingAttribute.SchemaTypeName = new XmlQualifiedName("RatingType", ""); complexType.Attributes.Add(ratingAttribute); element.SchemaType = complexType; schema.Items.Add(element); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne); schemaSet.Add(schema); schemaSet.Compile(); XmlSchema compiledSchema = null; foreach (XmlSchema schema1 in schemaSet.Schemas()) { compiledSchema = schema1; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema.Write(Console.Out, nsmgr); }
protected virtual void Visit(XmlSchemaFractionDigitsFacet 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); }
/// <summary> /// Запись в новый XSD файл содержимого класса SeSchemaItem /// </summary> /// <param name="newXSDElement">Новый элемент в схеме</param> /// <param name="xs">Новый экземпляр схемы</param> public void SaveXSD(XmlSchemaElement newXSDElement, XmlSchema xs) { SetProperties(newXSDElement); if (Type == "") { XmlSchemaComplexType newSchemaType = new XmlSchemaComplexType(); newXSDElement.SchemaType = newSchemaType; XmlSchemaAll newAll = new XmlSchemaAll(); if (Properties != null) { Properties.SetPropAll(newAll); } newSchemaType.Particle = newAll; foreach (SeSchemaItem ssi in SchemaItemsChildren) { XmlSchemaElement newElement = new XmlSchemaElement(); newElement.Name = ssi.Name; ssi.SetProperties(newElement); if (ssi.Description != null && ssi.Description != "") { newElement.Annotation = SetAnnotation(ssi); } if (ssi.SchemaItemsChildren != null && ssi.SchemaItemsChildren.Count != 0) { if (ssi.SchemaItemsChildren[0].Name == "SimpleType") { XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(); newElement.SchemaType = simpleType; XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction(); simpleType.Content = restriction; restriction.BaseTypeName = new XmlQualifiedName(ssi.Type, "http://www.w3.org/2001/XMLSchema"); foreach (SeSchemaItem sstc in ssi.SchemaItemsChildren) { string facetName = sstc.Description.Split('-')[0]; string facetValue = sstc.Description.Split('-')[1]; if (facetName == "XmlSchemaMaxLengthFacet") { XmlSchemaMaxLengthFacet ml = new XmlSchemaMaxLengthFacet(); restriction.Facets.Add(ml); ml.Value = facetValue; } if (facetName == "XmlSchemaTotalDigitsFacet") { XmlSchemaTotalDigitsFacet ml = new XmlSchemaTotalDigitsFacet(); restriction.Facets.Add(ml); ml.Value = facetValue; } if (facetName == "XmlSchemaFractionDigitsFacet") { XmlSchemaFractionDigitsFacet ml = new XmlSchemaFractionDigitsFacet(); restriction.Facets.Add(ml); ml.Value = facetValue; } } } else { if (ssi.CheckToCommonTypes() == true) { newElement.SchemaTypeName = new XmlQualifiedName(ssi.Type, "http://www.w3.org/2001/XMLSchema"); } else { newElement.SchemaTypeName = new XmlQualifiedName(ssi.Type); }; } } else { if (ssi.CheckToCommonTypes() == true) { newElement.SchemaTypeName = new XmlQualifiedName(ssi.Type, "http://www.w3.org/2001/XMLSchema"); } else { newElement.SchemaTypeName = new XmlQualifiedName(ssi.Type); } } newAll.Items.Add(newElement); } } else { if (CheckToCommonTypes() == true) { newXSDElement.SchemaTypeName = new XmlQualifiedName(Type, "http://www.w3.org/2001/XMLSchema"); } else { newXSDElement.SchemaTypeName = new XmlQualifiedName(Type); }; } }