public static ASLinkFile LoadFromStream(Stream stream, bool throwOnValidationError)
        {
            ASLinkFile result;

            try
            {
                using (ASLinkFile.NonClosingStreamWrapper nonClosingStreamWrapper = new ASLinkFile.NonClosingStreamWrapper(stream))
                {
                    XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
                    xmlReaderSettings.ValidationType          = ValidationType.Schema;
                    xmlReaderSettings.ValidationFlags        |= XmlSchemaValidationFlags.ReportValidationWarnings;
                    xmlReaderSettings.DtdProcessing           = DtdProcessing.Prohibit;
                    xmlReaderSettings.MaxCharactersInDocument = 4096L;
                    xmlReaderSettings.Schemas.Add("http://schemas.microsoft.com/analysisservices/linkfile", new XmlTextReader("<?xml version='1.0' encoding='utf-8'?> \r\n<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://schemas.microsoft.com/analysisservices/linkfile' elementFormDefault='qualified'>\r\n  <xs:element name='ASLinkFile'>\r\n    <xs:complexType>\r\n      <xs:all>\r\n        <xs:element name='Server' type='xs:string'/> \r\n        <xs:element name='Database' type='xs:string' />\r\n        <xs:element name='Description' type='xs:string' minOccurs='0'/>\r\n      </xs:all>\r\n      <xs:attribute name='allowDelegation' type='xs:boolean' default='false'/>\r\n    </xs:complexType>\r\n  </xs:element>\r\n</xs:schema>", XmlNodeType.Document, null));
                    xmlReaderSettings.ValidationEventHandler += delegate(object sender, ValidationEventArgs args)
                    {
                        throw args.Exception;
                    };
                    using (XmlReader xmlReader = XmlReader.Create(nonClosingStreamWrapper, xmlReaderSettings))
                    {
                        result = ASLinkFile.LoadFromXmlReader(xmlReader);
                    }
                }
            }
            catch (XmlSchemaException ex)
            {
                if (throwOnValidationError)
                {
                    throw;
                }
                result = ASLinkFile.CreateMalformed(ex);
            }
            return(result);
        }
 public void SaveToStream(Stream stream)
 {
     using (ASLinkFile.NonClosingStreamWrapper nonClosingStreamWrapper = new ASLinkFile.NonClosingStreamWrapper(stream))
     {
         using (XmlTextWriter xmlTextWriter = new XmlTextWriter(nonClosingStreamWrapper, Encoding.UTF8))
         {
             XmlDocument xmlDocument = this.CreateXmlDocument();
             xmlDocument.Save(xmlTextWriter);
         }
     }
 }