04d09502a53a376c4d7b6f8d763ce68172aeb2da
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / Dom / XmlProcessingInstruction.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlProcessingInstruction.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 namespace System.Xml {
9     using System;
10     using System.IO;
11     using System.Diagnostics;
12     using System.Text;
13     using System.Xml.XPath;
14
15     // Represents a processing instruction, which XML defines to keep
16     // processor-specific information in the text of the document.
17     public class XmlProcessingInstruction : XmlLinkedNode {
18         string target;
19         string data;
20
21         protected internal XmlProcessingInstruction( string target, string data, XmlDocument doc ) : base( doc ) {
22             this.target = target;
23             this.data = data;
24         }
25
26         // Gets the name of the node.
27         public override String Name {
28             get {
29                 if (target != null)
30                     return target;
31                 return String.Empty;
32             }
33         }
34
35         // Gets the name of the current node without the namespace prefix.
36         public override string LocalName {
37             get { return Name;}
38         }
39
40         // Gets or sets the value of the node.
41         public override String Value {
42             get { return data;}
43             set { Data = value; } //use Data instead of data so that event will be fired
44         }
45
46         // Gets the target of the processing instruction.
47         public String Target {
48             get { return target;}
49         }
50
51         // Gets or sets the content of processing instruction,
52         // excluding the target.
53         public String Data {
54             get { return data;}
55             set { 
56                 XmlNode parent = ParentNode;
57                 XmlNodeChangedEventArgs args = GetEventArgs( this, parent, parent, data, value, XmlNodeChangedAction.Change );
58                 if (args != null)
59                     BeforeEvent( args );
60                 data = value;
61                 if (args != null)
62                     AfterEvent( args );
63             }
64         }
65
66         // Gets or sets the concatenated values of the node and
67         // all its children.
68         public override string InnerText { 
69             get { return data;}
70             set { Data = value; } //use Data instead of data so that change event will be fired
71         }
72
73         // Gets the type of the current node.
74         public override XmlNodeType NodeType {
75             get { return XmlNodeType.ProcessingInstruction;}
76         }
77
78         // Creates a duplicate of this node.
79         public override XmlNode CloneNode(bool deep) {
80             Debug.Assert( OwnerDocument != null );
81             return OwnerDocument.CreateProcessingInstruction( target, data );
82         }
83
84         // Saves the node to the specified XmlWriter.
85         public override void WriteTo(XmlWriter w) {
86             w.WriteProcessingInstruction(target, data);
87         }
88
89         // Saves all the children of the node to the specified XmlWriter.
90         public override void WriteContentTo(XmlWriter w) {
91             // Intentionally do nothing
92         }
93
94         internal override string XPLocalName { get { return Name; } }
95         internal override XPathNodeType XPNodeType { get { return XPathNodeType.ProcessingInstruction; } }
96     }
97 }