Пример #1
0
        /// <summary>
        /// Write a documentation file for a simple type.
        /// </summary>
        /// <param name="schema">Parent schema of the simple type.</param>
        /// <param name="simpleType">The simple type.</param>
        private void WriteSimpleTypeDoc(XmlSchema schema, XmlSchemaSimpleType simpleType)
        {
            string htmlFile = this.GetSchemaHtmlFile(schema, String.Concat("simple_type_", simpleType.Name));

            XmlTextWriter writer = null;
            try
            {
                writer = StartHtmlWriter(htmlFile, String.Format("{0} (Simple Type)", simpleType.Name), "simpleTypeHeader");

                writer.WriteStartElement("dl");

                // description
                this.WriteDescription(simpleType, writer);

                // details
                if (simpleType.Content is XmlSchemaSimpleTypeRestriction)
                {
                    XmlSchemaSimpleTypeRestriction simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)simpleType.Content;

                    if (simpleTypeRestriction.Facets.Count > 0)
                    {
                        XmlSchemaObject firstFacet = simpleTypeRestriction.Facets[0];

                        if (firstFacet is XmlSchemaEnumerationFacet)
                        {
                            writer.WriteStartElement("dt");
                            writer.WriteString("Enumeration Type");
                            writer.WriteEndElement();

                            writer.WriteStartElement("dd");
                            bool first = true;
                            writer.WriteString("Possible values: {");
                            foreach (XmlSchemaEnumerationFacet enumerationFacet in simpleTypeRestriction.Facets)
                            {
                                if (first)
                                {
                                    first = false;
                                }
                                else
                                {
                                    writer.WriteString(", ");
                                }
                                writer.WriteString(enumerationFacet.Value);
                            }
                            writer.WriteString("}");
                            writer.WriteEndElement();
                        }
                        else if (firstFacet is XmlSchemaPatternFacet)
                        {
                            XmlSchemaPatternFacet patternFacet = (XmlSchemaPatternFacet)firstFacet;

                            writer.WriteStartElement("dt");
                            writer.WriteString("Pattern Type");
                            writer.WriteEndElement();

                            writer.WriteStartElement("dd");
                            writer.WriteString(String.Format("Must match the regular expression: '{0}'.", patternFacet.Value));
                            writer.WriteEndElement();
                        }
                        else // some other base
                        {
                            writer.WriteStartElement("dt");
                            if (simpleTypeRestriction.BaseTypeName.Namespace == XmlSchemaNamespace)
                            {
                                writer.WriteString("xs:");
                            }
                            writer.WriteString(simpleTypeRestriction.BaseTypeName.Name);
                            writer.WriteString(" Type");
                            writer.WriteEndElement();

                            writer.WriteStartElement("dd");
                            writer.WriteStartElement("ul");
                            writer.WriteStartElement("li");
                            foreach (XmlSchemaFacet facet in simpleTypeRestriction.Facets)
                            {
                                if (facet is XmlSchemaMaxInclusiveFacet)
                                {
                                    writer.WriteString(String.Format("xs:maxInclusive value='{0}'", ((XmlSchemaMaxInclusiveFacet)facet).Value));
                                }
                                else
                                {
                                    throw new ApplicationException(String.Format("Unknown simple type restriction facet type: '{0}'.", facet.GetType().ToString()));
                                }
                            }
                            writer.WriteEndElement();
                            writer.WriteEndElement();
                            writer.WriteEndElement();
                        }
                    }
                }
                else
                {
                    throw new ApplicationException(String.Format("Unknown simple type content type: '{0}'.", simpleType.GetType().ToString()));
                }

                // see also
                this.WriteSeeAlso(schema, simpleType, writer);

                // end dl element
                writer.WriteEndElement();

                EndHtmlWriter(writer);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
 private void Write34_XmlSchemaSimpleType(string n, string ns, XmlSchemaSimpleType o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(XmlSchemaSimpleType)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.EscapeName = false;
         base.WriteStartElement(n, ns, o, false, o.Namespaces);
         if (needType)
         {
             base.WriteXsiType("XmlSchemaSimpleType", "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("name", "", o.Name);
         if (o.Final != XmlSchemaDerivationMethod.None)
         {
             base.WriteAttribute("final", "", this.Write7_XmlSchemaDerivationMethod(o.Final));
         }
         this.Write11_XmlSchemaAnnotation("annotation", "http://www.w3.org/2001/XMLSchema", o.Annotation, false, false);
         if (o.Content is XmlSchemaSimpleTypeUnion)
         {
             this.Write33_XmlSchemaSimpleTypeUnion("union", "http://www.w3.org/2001/XMLSchema", (XmlSchemaSimpleTypeUnion) o.Content, false, false);
         }
         else if (o.Content is XmlSchemaSimpleTypeRestriction)
         {
             this.Write32_XmlSchemaSimpleTypeRestriction("restriction", "http://www.w3.org/2001/XMLSchema", (XmlSchemaSimpleTypeRestriction) o.Content, false, false);
         }
         else if (o.Content is XmlSchemaSimpleTypeList)
         {
             this.Write17_XmlSchemaSimpleTypeList("list", "http://www.w3.org/2001/XMLSchema", (XmlSchemaSimpleTypeList) o.Content, false, false);
         }
         else if (o.Content != null)
         {
             throw base.CreateUnknownTypeException(o.Content);
         }
         base.WriteEndElement(o);
     }
 }