public void WriteXml(XmlWriter xmlWriter) { StringWriter w = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter writer = new XmlTextWriter(w); this.schema.Write(writer); writer.Flush(); byte[] bytes = new UTF8Encoding().GetBytes(w.ToString()); XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas { MaxDepth = 0x20, MaxStringContentLength = 0x2000, MaxArrayLength = 0x4000, MaxBytesPerRead = 0x1000, MaxNameTableCharCount = 0x4000 }; XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(bytes, 0, bytes.GetLength(0), null, quotas, null); if ((reader.MoveToContent() == XmlNodeType.Element) && (reader.Name == "xs:schema")) { xmlWriter.WriteNode(reader, false); } reader.Close(); }