The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.XsltOld \ TextOnlyOutput

  1. //------------------------------------------------------------------------------
  2. // <copyright file="TextOnlyOutput.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Xml.Xsl.XsltOld
  16. {
  17.     using Res = System.Xml.Utils.Res;
  18.     using System;
  19.     using System.IO;
  20.     using System.Xml;
  21.     using System.Xml.XPath;
  22.     using System.Text;
  23.     using System.Collections;
  24.    
  25.     internal class TextOnlyOutput : RecordOutput
  26.     {
  27.         private Processor processor;
  28.         private TextWriter writer;
  29.        
  30.         internal XsltOutput Output {
  31.             get { return this.processor.Output; }
  32.         }
  33.        
  34.         public TextWriter Writer {
  35.             get { return this.writer; }
  36.         }
  37.        
  38.         //
  39.         // Constructor
  40.         //
  41.        
  42.         internal TextOnlyOutput(Processor processor, Stream stream)
  43.         {
  44.             if (stream == null) {
  45.                 throw new ArgumentNullException("stream");
  46.             }
  47.            
  48.             this.processor = processor;
  49.             this.writer = new StreamWriter(stream, Output.Encoding);
  50.         }
  51.        
  52.         internal TextOnlyOutput(Processor processor, TextWriter writer)
  53.         {
  54.             if (writer == null) {
  55.                 throw new ArgumentNullException("writer");
  56.             }
  57.            
  58.             this.processor = processor;
  59.             this.writer = writer;
  60.         }
  61.        
  62.         //
  63.         // RecordOutput interface method implementation
  64.         //
  65.        
  66.         public Processor.OutputResult RecordDone(RecordBuilder record)
  67.         {
  68.             BuilderInfo mainNode = record.MainNode;
  69.            
  70.             switch (mainNode.NodeType) {
  71.                 case XmlNodeType.Text:
  72.                 case XmlNodeType.Whitespace:
  73.                 case XmlNodeType.SignificantWhitespace:
  74.                     this.writer.Write(mainNode.Value);
  75.                     break;
  76.                 default:
  77.                     break;
  78.             }
  79.            
  80.             record.Reset();
  81.             return Processor.OutputResult.Continue;
  82.         }
  83.        
  84.         public void TheEnd()
  85.         {
  86.             this.writer.Flush();
  87.         }
  88.     }
  89. }

Developer Fusion