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