コード例 #1
0
ファイル: xmlschema.cs プロジェクト: SSCLI/sscli_20021101
    }         //WriteExampleParticle()

    // Write the examples text values
    public static void WriteExampleValue(object schemaType, XmlTextWriter myXmlTextWriter)
    {
        Random            random   = new Random();
        XmlSchemaDatatype datatype =
            (schemaType is XmlSchemaSimpleType) ?
            ((XmlSchemaSimpleType)schemaType).Datatype : (XmlSchemaDatatype)schemaType;

        // Consult the XSD to CLR conversion table for the correct type mappings
        Type type = datatype.ValueType;

        if (type == typeof(bool))
        {
            myXmlTextWriter.WriteString("true");
        }
        else if (type == typeof(int) || type == typeof(long))
        {
            myXmlTextWriter.WriteString(random.Next(100).ToString());
        }
        else if (type == typeof(float) || type == typeof(decimal))
        {
            myXmlTextWriter.WriteString(((float)random.Next(100) / (float)random.Next(10, 20)).ToString("#.00"));
        }
        else if (type == typeof(System.Xml.XmlQualifiedName))
        {
            myXmlTextWriter.WriteString("qualified_name" + random.Next(100).ToString());
        }
        else if (type == typeof(DateTime))
        {
            myXmlTextWriter.WriteString("12-12-2002");
        }
        else if (type == typeof(string))
        {
            myXmlTextWriter.WriteString("ExampleString" + random.Next(100).ToString());
        }
        // Handle the 'xsd:positiveInteger' XSD type in the SOMsample.xsd
        else if (type == typeof(System.UInt64))
        {
            //positiveInteger
            myXmlTextWriter.WriteString(random.Next(100).ToString());
        }
        else
        {
            myXmlTextWriter.WriteString("Not Implemented for this datatype: " + datatype.ToString());
        }
    } //WriteExampleValue()
コード例 #2
0
        // Write the examples text values
        protected void WriteExampleValue(string appliesTo,
                                         object schemaType,
                                         XmlWriter writer)
        {
            XmlSchemaDatatype   datatype   = null;
            XmlSchemaSimpleType simpleType = schemaType as XmlSchemaSimpleType;

            if (simpleType != null)
            {
                datatype = ((XmlSchemaSimpleType)schemaType).Datatype;

                if (simpleType.Content is XmlSchemaSimpleTypeRestriction)
                {
                    XmlSchemaSimpleTypeRestriction restriction =
                        (XmlSchemaSimpleTypeRestriction)simpleType.Content;
                    ArrayList enumElements = new ArrayList();
                    foreach (XmlSchemaFacet facet in restriction.Facets)
                    {
                        if (facet is XmlSchemaEnumerationFacet)
                        {
                            enumElements.Add(((XmlSchemaEnumerationFacet)facet).Value);
                        }
                    }
                    if (enumElements.Count > 0)
                    {
                        writer.WriteString
                            ((string)enumElements[fRandom.Next(enumElements.Count - 1)]);
                        return;
                    }
                }
            }
            else
            {
                datatype = (XmlSchemaDatatype)schemaType;
            }

            // Consult the XSD to CLR conversion table for the correct type mappings
            Type type = datatype.ValueType;

            if (type == typeof(bool))
            {
                writer.WriteString("true");
            }
            else if (type == typeof(int) || type == typeof(long))
            {
                writer.WriteString(fRandom.Next(10).ToString());
            }
            else if (type == typeof(float) || type == typeof(decimal))
            {
                writer.WriteString(((float)(fRandom.Next(10000) / 100f)).ToString("#.00"));
            }
            else if (type == typeof(XmlQualifiedName))
            {
                writer.WriteString("qualified_name" + fRandom.Next(100).ToString());
            }
            else if (type == typeof(DateTime))
            {
                writer.WriteString("12-12-2001");
            }
            else if (type == typeof(string))
            {
                if (appliesTo.StartsWith("SIF_"))
                {
                    appliesTo = appliesTo.Substring(4);
                }
                writer.WriteString("Example " + appliesTo + fRandom.Next(100).ToString());
            }
            // Handle the 'xsd:positiveInteger' XSD type in the SOMsample.xsd
            else if (type == typeof(UInt64))
            {
                //positiveInteger
                writer.WriteString(fRandom.Next(100).ToString());
            }
            else
            {
                writer.WriteString("Not Implemented for this datatype: " + datatype.ToString());
            }
        }