示例#1
0
        internal XSTotalDigitsFacet(XmlSchemaTotalDigitsFacet totalDigitsFacet)
        {
            _facet = totalDigitsFacet;

            if (_facet.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }
        }
示例#2
0
        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);
        }
示例#3
0
        private static XmlSchemaSimpleTypeRestriction ExtractNumberAndIntegerFacets(JsonSchema jSchema, TypeKeyword type)
        {
            XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction();
            double?minValue          = GetterExtensions.Minimum(jSchema);
            double?minExclusiveValue = GetterExtensions.ExclusiveMinimum(jSchema);

            if (type.Value == JsonSchemaType.Number)
            {
                content.BaseTypeName = new XmlQualifiedName("decimal", XML_SCHEMA_NS);
            }
            else if (type.Value == JsonSchemaType.Integer)
            {
                if (minValue != null && minValue == 1)
                {
                    content.BaseTypeName = new XmlQualifiedName("positiveInteger", XML_SCHEMA_NS);
                }
                else
                {
                    content.BaseTypeName = new XmlQualifiedName("integer", XML_SCHEMA_NS);
                }
            }

            double?maxValue          = GetterExtensions.Maximum(jSchema);
            double?maxExclusiveValue = GetterExtensions.ExclusiveMaximum(jSchema);

            Regex regex = new Regex("^[9]+$");

            if ((minValue != null && maxValue != null) && Math.Abs((double)minValue).Equals(maxValue) && regex.IsMatch(maxValue.ToString()))
            {
                XmlSchemaTotalDigitsFacet facet = new XmlSchemaTotalDigitsFacet
                {
                    Value = FormatDouble(maxValue.ToString().Length),
                };
                content.Facets.Add(facet);
            }
            else
            {
                if (minValue != null || minExclusiveValue != null)
                {
                    if (minValue != null)
                    {
                        XmlSchemaMinInclusiveFacet facet = new XmlSchemaMinInclusiveFacet
                        {
                            Value = FormatDouble((double)minValue),
                        };
                        content.Facets.Add(facet);
                    }
                    else
                    {
                        XmlSchemaMinExclusiveFacet facet = new XmlSchemaMinExclusiveFacet
                        {
                            Value = FormatDouble((double)minExclusiveValue),
                        };
                        content.Facets.Add(facet);
                    }
                }

                if (maxValue != null || maxExclusiveValue != null)
                {
                    if (maxValue != null)
                    {
                        XmlSchemaMaxInclusiveFacet maxInclusiveFacet = new XmlSchemaMaxInclusiveFacet
                        {
                            Value = FormatDouble((double)maxValue),
                        };
                        content.Facets.Add(maxInclusiveFacet);
                    }
                    else
                    {
                        XmlSchemaMaxExclusiveFacet maxExclusiveFacet = new XmlSchemaMaxExclusiveFacet
                        {
                            Value = FormatDouble((double)maxExclusiveValue),
                        };
                        content.Facets.Add(maxExclusiveFacet);
                    }
                }
            }

            return(content);
        }
 protected override void Visit(XmlSchemaTotalDigitsFacet facet)
 {
     AddLeaf(SimpleTypeStructureNodeType.FacetTotalDigits, 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);
    }
示例#6
0
 protected virtual void Visit(XmlSchemaTotalDigitsFacet facet)
 {
 }
示例#7
0
        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);
        }
示例#8
0
        /// <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);
                };
            }
        }