1 using System;
2 using System.Collections;
3 using System.Text;
4
5
6
7
8
9 namespace System.Dom
10 {
11 public abstract class CharacterData : Node
12 {
13 public suppress CharacterData(const CharacterData&);
14 public suppress CharacterData(CharacterData&&);
15 public CharacterData(NodeType nodeType_, const ustring& name_) :
16 base(nodeType_, name_)
17 {
18 }
19 public CharacterData(NodeType nodeType_, const ustring& name_, const ustring& data_) :
20 base(nodeType_, name_), data(data_)
21 {
22 }
23 public suppress CharacterData& operator=(const CharacterData&);
24 public suppress CharacterData& operator=(CharacterData&&);
25 public const ustring& Data() const
26 {
27 return data;
28 }
29 public ustring& Data()
30 {
31 return data;
32 }
33 public override void Write(CodeFormatter& formatter)
34 {
35 formatter.Write(ToUtf8(XmlCharDataEscape(data)));
36 }
37 public override bool ValueContainsNewLine() const
38 {
39 return data.Find('\n') != -1;
40 }
41 private ustring data;
42 }
43 public class Text : CharacterData
44 {
45 public suppress Text(const Text&);
46 public suppress Text(Text&&);
47 public Text() :
48 base(NodeType.textNode, u"text")
49 {
50 }
51 public explicit Text(const ustring& data_) :
52 base(NodeType.textNode, u"text", data_)
53 {
54 }
55 public Text(NodeType nodeType_, const ustring& name_) :
56 base(nodeType_, name_)
57 {
58 }
59 public Text(NodeType nodeType_, const ustring& name_, const ustring& data_) :
60 base(nodeType_, name_, data_)
61 {
62 }
63 public suppress Text& operator=(const Text&);
64 public suppress Text& operator=(Text&&);
65 public override UniquePtr<Node> CloneNode(bool deep)
66 {
67 return UniquePtr<Node>(new Text(Data()));
68 }
69 public override void Accept(Visitor& visitor)
70 {
71 visitor.Visit(this);
72 }
73 }
74 public class EntityReference : CharacterData
75 {
76 public suppress EntityReference(const EntityReference&);
77 public suppress EntityReference(EntityReference&&);
78 public EntityReference() :
79 base(NodeType.entityReferenceNode, u"entity_refefrence")
80 {
81 }
82 public explicit EntityReference(const ustring& entityRef_) :
83 base(NodeType.entityReferenceNode, u"entity_refefrence", entityRef_)
84 {
85 }
86 public suppress EntityReference& operator=(const EntityReference&);
87 public suppress EntityReference& operator=(EntityReference&&);
88 public override void Write(CodeFormatter& formatter)
89 {
90 formatter.Write("&");
91 formatter.Write(ToUtf8(Data()));
92 formatter.Write(";");
93 }
94 public override UniquePtr<Node> CloneNode(bool deep)
95 {
96 return UniquePtr<Node>(new EntityReference(Data()));
97 }
98 public override void Accept(Visitor& visitor)
99 {
100 visitor.Visit(this);
101 }
102 }
103 public class CDataSection : Text
104 {
105 public suppress CDataSection(const CDataSection&);
106 public suppress CDataSection(CDataSection&&);
107 public CDataSection() :
108 base(NodeType.cdataSectionNode, u"cdata_section")
109 {
110 }
111 public explicit CDataSection(const ustring& data_) :
112 base(NodeType.cdataSectionNode, u"cdata_section", data_)
113 {
114 }
115 public suppress CDataSection& operator=(const CDataSection&);
116 public suppress CDataSection& operator=(CDataSection&&);
117 public override void Write(CodeFormatter& formatter)
118 {
119 formatter.Write("<![CDATA[");
120 formatter.Write(ToUtf8(Data()));
121 formatter.Write("]]>");
122 }
123 public override UniquePtr<Node> CloneNode(bool deep)
124 {
125 return UniquePtr<Node>(new CDataSection(Data()));
126 }
127 public override void Accept(Visitor& visitor)
128 {
129 visitor.Visit(this);
130 }
131 }
132 public class Comment : CharacterData
133 {
134 public suppress Comment(const Comment&);
135 public suppress Comment(Comment&&);
136 public Comment() :
137 base(NodeType.commentNode, u"comment")
138 {
139 }
140 public explicit Comment(const ustring& data_) :
141 base(NodeType.commentNode, u"comment", data_)
142 {
143 }
144 public suppress Comment& operator=(const Comment&);
145 public suppress Comment& operator=(Comment&&);
146 public override void Write(CodeFormatter& formatter)
147 {
148 formatter.Write("<!-- ");
149 formatter.Write(ToUtf8(Data()));
150 formatter.Write(" -->");
151 }
152 public override UniquePtr<Node> CloneNode(bool deep)
153 {
154 return UniquePtr<Node>(new Comment(Data()));
155 }
156 public override void Accept(Visitor& visitor)
157 {
158 visitor.Visit(this);
159 }
160 }
161 public class ProcessingInstruction : Node
162 {
163 public suppress ProcessingInstruction(const ProcessingInstruction&);
164 public suppress ProcessingInstruction(ProcessingInstruction&&);
165 public ProcessingInstruction(const ustring& target_, const ustring& data_) :
166 base(NodeType.processingInstructionNode, u"processing_instruction"), target(target_), data(data_)
167 {
168 }
169 public suppress ProcessingInstruction& operator=(const ProcessingInstruction&);
170 public suppress ProcessingInstruction& operator=(ProcessingInstruction&&);
171 public const ustring& Target() const
172 {
173 return target;
174 }
175 public const ustring& Data() const
176 {
177 return data;
178 }
179 public override void Write(CodeFormatter& formatter)
180 {
181 formatter.WriteLine("<?" + ToUtf8(target) + " " + ToUtf8(data) + "?>");
182 }
183 public override UniquePtr<Node> CloneNode(bool deep)
184 {
185 return UniquePtr<Node>(new ProcessingInstruction(target, data));
186 }
187 public override void Accept(Visitor& visitor)
188 {
189 visitor.Visit(this);
190 }
191 private ustring target;
192 private ustring data;
193 }
194 public ustring XmlCharDataEscape(const ustring& charData)
195 {
196 ustring result;
197 for (uchar c : charData)
198 {
199 switch (c)
200 {
201 case '<': result.Append(u"<");
202 break;
203 case '&': result.Append(u"&");
204 break;
205 default: result.Append(c, 1);
206 break;
207 }
208 }
209 return result;
210 }
211 }