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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlProcessingInstruction.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.IO;
  19.     using System.Diagnostics;
  20.     using System.Text;
  21.     using System.Xml.XPath;
  22.    
  23.     // Represents a processing instruction, which XML defines to keep
  24.     // processor-specific information in the text of the document.
  25.     public class XmlProcessingInstruction : XmlLinkedNode
  26.     {
  27.         string target;
  28.         string data;
  29.        
  30.         protected internal XmlProcessingInstruction(string target, string data, XmlDocument doc) : base(doc)
  31.         {
  32.             this.target = target;
  33.             this.data = data;
  34.         }
  35.        
  36.         // Gets the name of the node.
  37.         public override string Name {
  38.             get {
  39.                 if (target != null)
  40.                     return target;
  41.                 return String.Empty;
  42.             }
  43.         }
  44.        
  45.         // Gets the name of the current node without the namespace prefix.
  46.         public override string LocalName {
  47.             get { return Name; }
  48.         }
  49.        
  50.         // Gets or sets the value of the node.
  51.         public override string Value {
  52.             get { return data; }
  53.             set { Data = value; }
  54.         }
  55.         //use Data instead of data so that event will be fired
  56.        
  57.         // Gets the target of the processing instruction.
  58.         public string Target {
  59.             get { return target; }
  60.         }
  61.        
  62.         // Gets or sets the content of processing instruction,
  63.         // excluding the target.
  64.         public string Data {
  65.             get { return data; }
  66.             set {
  67.                 XmlNode parent = ParentNode;
  68.                 XmlNodeChangedEventArgs args = GetEventArgs(this, parent, parent, data, value, XmlNodeChangedAction.Change);
  69.                 if (args != null)
  70.                     BeforeEvent(args);
  71.                 data = value;
  72.                 if (args != null)
  73.                     AfterEvent(args);
  74.             }
  75.         }
  76.        
  77.         // Gets or sets the concatenated values of the node and
  78.         // all its children.
  79.         public override string InnerText {
  80.             get { return data; }
  81.             set { Data = value; }
  82.         }
  83.         //use Data instead of data so that change event will be fired
  84.        
  85.         // Gets the type of the current node.
  86.         public override XmlNodeType NodeType {
  87.             get { return XmlNodeType.ProcessingInstruction; }
  88.         }
  89.        
  90.         // Creates a duplicate of this node.
  91.         public override XmlNode CloneNode(bool deep)
  92.         {
  93.             Debug.Assert(OwnerDocument != null);
  94.             return OwnerDocument.CreateProcessingInstruction(target, data);
  95.         }
  96.        
  97.         // Saves the node to the specified XmlWriter.
  98.         public override void WriteTo(XmlWriter w)
  99.         {
  100.             w.WriteProcessingInstruction(target, data);
  101.         }
  102.        
  103.         // Saves all the children of the node to the specified XmlWriter.
  104.         public override void WriteContentTo(XmlWriter w)
  105.         {
  106.             // Intentionally do nothing
  107.         }
  108.        
  109.         internal override string XPLocalName {
  110.             get { return Name; }
  111.         }
  112.         internal override XPathNodeType XPNodeType {
  113.             get { return XPathNodeType.ProcessingInstruction; }
  114.         }
  115.     }
  116. }

Developer Fusion