/// <summary> /// Runs this process and performs the appropriate actions. /// </summary> public override void Run() { // Verify data. if (this.OutputDirectory == null) { this.OutputDirectory = this.OutputFile.Directory; } // Verify that the input file exists since if we can't, it is // meaningless to continue. if (!this.InputFile.Exists) { throw new FileNotFoundException( "Cannot find input file.", this.InputFile.FullName); } // We use the identity XML writer to copy out the resulting XML // stream but use an intelligent loader to do all the work. This // way, we can reuse much of the IO functionality without // cluttering our code. using (XmlReader xmlReader = this.CreateXmlReader()) using (XmlIdentityWriter xmlWriter = this.CreateXmlWriter()) { // Using the identity XML writer will go through the entire // reader XML and write it out. This will cause the gathering // reader to load in the various XInclude elements and also // copy the media files to the appropriate place. xmlWriter.Load(xmlReader); } }
public void SingleTag() { // Arrange const string xml = "<a />"; // Act var settings = new XmlWriterSettings { OmitXmlDeclaration = true, }; var stringWriter = new StringWriter(); using (var stringReader = new StringReader(xml)) { using (XmlReader xmlReader = XmlReader.Create(stringReader)) { using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings)) { using (var identityWriter = new XmlIdentityWriter(xmlWriter)) { identityWriter.Load(xmlReader); } } } } // Assert string actual = stringWriter.ToString(); Assert.AreEqual(xml, actual); }
/// <summary> /// Writes the XML results. /// </summary> /// <param name="xml">The input XML.</param> /// <returns>The resulting XML from an identity write.</returns> private static string WriteXmlResults(string xml) { // Set up the XML writing to produce consistent results. var writerSettings = new XmlWriterSettings { OmitXmlDeclaration = true, }; var stringWriter = new StringWriter(); // Set up the reader by chaining into the include reader. using (var stringReader = new StringReader(xml)) { using (XmlReader xmlReader = XmlReader.Create(stringReader)) { using (var includeReader = new TestXIncludeReader(xmlReader)) { // Set up the identity writer so we can verify the results // using string. using ( XmlWriter xmlWriter = XmlWriter.Create(stringWriter, writerSettings)) { using (var identityWriter = new XmlIdentityWriter(xmlWriter)) { identityWriter.Load(includeReader); } } } } } // Pull out the resulting string. string results = stringWriter.ToString(); // Report the input and output. Console.WriteLine(" Input XML: " + xml); Console.WriteLine("Output XML: " + results); // Return the results. return(results); }