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);
        }
        private static ASLinkFile LoadFromXmlReader(XmlReader linkFileReader)
        {
            ASLinkFile aSLinkFile = new ASLinkFile();

            while (linkFileReader.Read())
            {
                if (linkFileReader.NodeType == XmlNodeType.Element && linkFileReader.NamespaceURI.Equals("http://schemas.microsoft.com/analysisservices/linkfile"))
                {
                    if (linkFileReader.LocalName.Equals("ASLinkFile"))
                    {
                        if (linkFileReader.MoveToAttribute("allowDelegation"))
                        {
                            aSLinkFile.IsDelegationAllowed = linkFileReader.ReadContentAsBoolean();
                        }
                    }
                    else if (linkFileReader.LocalName.Equals("Server"))
                    {
                        aSLinkFile.Server = linkFileReader.ReadString();
                    }
                    else if (linkFileReader.LocalName.Equals("Database"))
                    {
                        aSLinkFile.Database = linkFileReader.ReadString();
                    }
                    else if (linkFileReader.LocalName.Equals("Description"))
                    {
                        aSLinkFile.Description = linkFileReader.ReadString();
                    }
                }
            }
            return(aSLinkFile);
        }
 public static ASLinkFile LoadFromStream(Stream stream)
 {
     return(ASLinkFile.LoadFromStream(stream, false));
 }