private XmlValidatingLoader CreateXmlValidatingLoader(FileInfo configFile)
        {
            XmlValidatingLoader loader = new XmlValidatingLoader(new XmlTextReader(configFile.FullName));

            loader.ValidationEventHandler += handler;
            return(loader);
        }
        private XmlValidatingLoader CreateXmlValidatingLoader(FileInfo configFile)
        {
            XmlDocument doc = new XmlDocument();

            // Run the config file through the preprocessor.
            XmlReaderSettings settings2 = new XmlReaderSettings();

            settings2.ProhibitDtd = false;
            using (XmlReader reader = XmlReader.Create(configFile.FullName, settings2))
            {
                using (XmlWriter writer = doc.CreateNavigator().AppendChild())
                {
                    preprocessor.PreProcess(reader, writer, new XmlUrlResolver(), null);
                }
            }
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ConformanceLevel = ConformanceLevel.Auto;
            settings.ProhibitDtd      = false;
            settings.IgnoreWhitespace = true;
            // Wrap the preprocessed output with an XmlValidatingLoader
            XmlValidatingLoader loader =
                new XmlValidatingLoader(XmlReader.Create(doc.CreateNavigator().ReadSubtree(), settings));

            loader.ValidationEventHandler += handler;
            return(loader);
        }
		private static XmlValidatingLoader XmlValidatingLoader(string xml)
		{
			XmlTextReader xr = new XmlTextReader(new StringReader(xml));
			XmlValidatingLoader loader = new XmlValidatingLoader(xr);
			loader.ValidationEventHandler += new ValidationEventHandler(Handler);
			loader.AddSchema(LoadSchema());
			return loader;
		}
Example #4
0
        private XmlDocument AttemptLoadConfiguration(FileInfo configFile)
        {
            XmlValidatingLoader loader = CreateXmlValidatingLoader(configFile);

            try
            {
                return(loader.Load());
            }
            catch (XmlException ex)
            {
                throw new ConfigurationException("The configuration file contains invalid xml: " + configFile.FullName, ex);
            }
        }
		public void ShouldBeAbleToLoadXmlWithDTD()
		{
			tempfile = TempFileUtil.CreateTempFile("config", "project1.xml", @"<project name=""p1"" />");
			string xml = 
@"<!DOCTYPE cruisecontrol [ 
	<!ENTITY project1 SYSTEM ""file:" + tempfile + @""">
]> 
<cruisecontrol>&project1;</cruisecontrol>";
			XmlTextReader xr = new XmlTextReader(new StringReader(xml));
			XmlValidatingLoader loader = new XmlValidatingLoader(xr);
			XmlDocument doc = loader.Load();
			Assert.IsNotNull(doc, "Unable to load document because it is not valid according to reader");
			IConfiguration config = new NetReflectorConfigurationReader().Read(doc, null);
			Assert.IsNotNull(config.Projects["p1"]);
		}
		private XmlValidatingLoader CreateXmlValidatingLoader(FileInfo configFile)
		{
            XmlDocument doc = new XmlDocument();
            
            // Run the config file through the preprocessor.
            XmlReaderSettings settings2 = new XmlReaderSettings();
            settings2.ProhibitDtd = false;
            using (XmlReader reader = XmlReader.Create(configFile.FullName, settings2))
            {
                using( XmlWriter writer = doc.CreateNavigator().AppendChild() )
                {
                    preprocessor.PreProcess(reader, writer, new XmlUrlResolver(), null);
                }
            }
            XmlReaderSettings settings = new XmlReaderSettings();
		    settings.ConformanceLevel = ConformanceLevel.Auto;
		    settings.ProhibitDtd = false;
		    settings.IgnoreWhitespace = true;
            // Wrap the preprocessed output with an XmlValidatingLoader
		    XmlValidatingLoader loader =
		        new XmlValidatingLoader( XmlReader.Create( doc.CreateNavigator().ReadSubtree(), settings ) );
			loader.ValidationEventHandler += handler;
			return loader;
		}
 private XmlValidatingLoader CreateXmlValidatingLoader(FileInfo configFile)
 {
     XmlValidatingLoader loader = new XmlValidatingLoader(new XmlTextReader(configFile.FullName));
     loader.ValidationEventHandler += handler;
     return loader;
 }