The Labs \ Source Viewer \ SSCLI \ System.Xml \ XmlCDataSection

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlCDATASection.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
  16. {
  17.     using System;
  18.     using System.Text;
  19.     using System.Diagnostics;
  20.     using System.Xml.XPath;
  21.    
  22.     // Used to quote or escape blocks of text to keep that text from being
  23.     // interpreted as markup language.
  24.     public class XmlCDataSection : XmlCharacterData
  25.     {
  26.         protected internal XmlCDataSection(string data, XmlDocument doc) : base(data, doc)
  27.         {
  28.         }
  29.        
  30.         // Gets the name of the node.
  31.         public override string Name {
  32.             get { return OwnerDocument.strCDataSectionName; }
  33.         }
  34.        
  35.         // Gets the name of the node without the namespace prefix.
  36.         public override string LocalName {
  37.             get { return OwnerDocument.strCDataSectionName; }
  38.         }
  39.        
  40.         // Gets the type of the current node.
  41.         public override XmlNodeType NodeType {
  42.             get { return XmlNodeType.CDATA; }
  43.         }
  44.        
  45.         public override XmlNode ParentNode {
  46.             get {
  47.                 switch (parentNode.NodeType) {
  48.                     case XmlNodeType.Document:
  49.                         return null;
  50.                     case XmlNodeType.Text:
  51.                     case XmlNodeType.CDATA:
  52.                     case XmlNodeType.Whitespace:
  53.                     case XmlNodeType.SignificantWhitespace:
  54.                         XmlNode parent = parentNode.parentNode;
  55.                         while (parent.IsText) {
  56.                             parent = parent.parentNode;
  57.                         }
  58.                         return parent;
  59.                     default:
  60.                         return parentNode;
  61.                 }
  62.             }
  63.         }
  64.        
  65.         // Creates a duplicate of this node.
  66.         public override XmlNode CloneNode(bool deep)
  67.         {
  68.             Debug.Assert(OwnerDocument != null);
  69.             return OwnerDocument.CreateCDataSection(Data);
  70.         }
  71.        
  72.         // Saves the node to the specified XmlWriter.
  73.         public override void WriteTo(XmlWriter w)
  74.         {
  75.             w.WriteCData(Data);
  76.         }
  77.        
  78.         // Saves the node to the specified XmlWriter.
  79.         public override void WriteContentTo(XmlWriter w)
  80.         {
  81.             // Intentionally do nothing
  82.         }
  83.        
  84.         internal override XPathNodeType XPNodeType {
  85.             get { return XPathNodeType.Text; }
  86.         }
  87.        
  88.         internal override bool IsText {
  89.             get { return true; }
  90.         }
  91.        
  92.         internal override XmlNode PreviousText {
  93.             get {
  94.                 if (parentNode.IsText) {
  95.                     return parentNode;
  96.                 }
  97.                 return null;
  98.             }
  99.         }
  100.     }
  101. }

Developer Fusion