public void TestSerializeSchema () { XmlSchema schema = new XmlSchema (); schema.Items.Add (new XmlSchemaAttribute ()); schema.Items.Add (new XmlSchemaAttributeGroup ()); schema.Items.Add (new XmlSchemaComplexType ()); schema.Items.Add (new XmlSchemaNotation ()); schema.Items.Add (new XmlSchemaSimpleType ()); schema.Items.Add (new XmlSchemaGroup ()); schema.Items.Add (new XmlSchemaElement ()); StringWriter sw = new StringWriter (); XmlTextWriter xtw = new XmlTextWriter (sw); xtw.QuoteChar = '\''; xtw.Formatting = Formatting.Indented; XmlSerializer xs = new XmlSerializer (schema.GetType ()); xs.Serialize (xtw, schema); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "<?xml version='1.0' encoding='utf-16'?>{0}" + "<xsd:schema xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>{0}" + " <xsd:attribute />{0}" + " <xsd:attributeGroup />{0}" + " <xsd:complexType />{0}" + " <xsd:notation />{0}" + " <xsd:simpleType />{0}" + " <xsd:group />{0}" + " <xsd:element />{0}" + "</xsd:schema>", Environment.NewLine), sw.ToString ()); }
private void Write66_XmlSchema(string n, string ns, XmlSchema o, bool isNullable, bool needType) { if (o == null) { if (isNullable) { base.WriteNullTagLiteral(n, ns); } } else { if (!needType && !(o.GetType() == typeof(XmlSchema))) { throw base.CreateUnknownTypeException(o); } base.EscapeName = false; base.WriteStartElement(n, ns, o, false, o.Namespaces); if (needType) { base.WriteXsiType("XmlSchema", "http://www.w3.org/2001/XMLSchema"); } if (o.AttributeFormDefault != XmlSchemaForm.None) { base.WriteAttribute("attributeFormDefault", "", this.Write6_XmlSchemaForm(o.AttributeFormDefault)); } if (o.BlockDefault != XmlSchemaDerivationMethod.None) { base.WriteAttribute("blockDefault", "", this.Write7_XmlSchemaDerivationMethod(o.BlockDefault)); } if (o.FinalDefault != XmlSchemaDerivationMethod.None) { base.WriteAttribute("finalDefault", "", this.Write7_XmlSchemaDerivationMethod(o.FinalDefault)); } if (o.ElementFormDefault != XmlSchemaForm.None) { base.WriteAttribute("elementFormDefault", "", this.Write6_XmlSchemaForm(o.ElementFormDefault)); } base.WriteAttribute("targetNamespace", "", o.TargetNamespace); base.WriteAttribute("version", "", o.Version); 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); } } XmlSchemaObjectCollection includes = o.Includes; if (includes != null) { for (int j = 0; j < includes.Count; j++) { XmlSchemaObject obj2 = includes[j]; if (obj2 is XmlSchemaRedefine) { this.Write64_XmlSchemaRedefine("redefine", "http://www.w3.org/2001/XMLSchema", (XmlSchemaRedefine) obj2, false, false); } else if (obj2 is XmlSchemaImport) { this.Write13_XmlSchemaImport("import", "http://www.w3.org/2001/XMLSchema", (XmlSchemaImport) obj2, false, false); } else if (obj2 is XmlSchemaInclude) { this.Write12_XmlSchemaInclude("include", "http://www.w3.org/2001/XMLSchema", (XmlSchemaInclude) obj2, false, false); } else if (obj2 != null) { throw base.CreateUnknownTypeException(obj2); } } } XmlSchemaObjectCollection items = o.Items; if (items != null) { for (int k = 0; k < items.Count; k++) { XmlSchemaObject obj3 = items[k]; if (obj3 is XmlSchemaElement) { this.Write52_XmlSchemaElement("element", "http://www.w3.org/2001/XMLSchema", (XmlSchemaElement) obj3, false, false); } else if (obj3 is XmlSchemaComplexType) { this.Write62_XmlSchemaComplexType("complexType", "http://www.w3.org/2001/XMLSchema", (XmlSchemaComplexType) obj3, false, false); } else if (obj3 is XmlSchemaSimpleType) { this.Write34_XmlSchemaSimpleType("simpleType", "http://www.w3.org/2001/XMLSchema", (XmlSchemaSimpleType) obj3, false, false); } else if (obj3 is XmlSchemaAttribute) { this.Write36_XmlSchemaAttribute("attribute", "http://www.w3.org/2001/XMLSchema", (XmlSchemaAttribute) obj3, false, false); } else if (obj3 is XmlSchemaAttributeGroup) { this.Write40_XmlSchemaAttributeGroup("attributeGroup", "http://www.w3.org/2001/XMLSchema", (XmlSchemaAttributeGroup) obj3, false, false); } else if (obj3 is XmlSchemaNotation) { this.Write65_XmlSchemaNotation("notation", "http://www.w3.org/2001/XMLSchema", (XmlSchemaNotation) obj3, false, false); } else if (obj3 is XmlSchemaGroup) { this.Write63_XmlSchemaGroup("group", "http://www.w3.org/2001/XMLSchema", (XmlSchemaGroup) obj3, false, false); } else if (obj3 is XmlSchemaAnnotation) { this.Write11_XmlSchemaAnnotation("annotation", "http://www.w3.org/2001/XMLSchema", (XmlSchemaAnnotation) obj3, false, false); } else if (obj3 != null) { throw base.CreateUnknownTypeException(obj3); } } } base.WriteEndElement(o); } }