1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
//
// System.Xml.XmlTextWriter
//
// Author:
// Kral Ferch <kral_ferch@hotmail.com>
//
// (C) 2002 Kral Ferch
//
using System;
namespace System.Xml
{
public abstract class XmlWriter
{
#region Fields
protected WriteState ws = WriteState.Start;
protected XmlNamespaceManager namespaceManager = new XmlNamespaceManager (new NameTable ());
#endregion
#region Constructors
protected XmlWriter () { }
#endregion
#region Properties
public abstract WriteState WriteState { get; }
public abstract string XmlLang { get; }
public abstract XmlSpace XmlSpace { get; }
#endregion
#region Methods
public abstract void Close ();
public abstract void Flush ();
public abstract string LookupPrefix (string ns);
[MonoTODO("DTDs must be implemented to use 'defattr' parameter.")]
public virtual void WriteAttributes (XmlReader reader, bool defattr)
{
if(reader == null)
throw new ArgumentException("null XmlReader specified.", "reader");
switch(reader.NodeType)
{
case XmlNodeType.XmlDeclaration:
// this method doesn't write "<?xml " and "?>", at least MS .NET Framework as yet.
XmlDeclaration decl = new XmlDeclaration("1.0", String.Empty, String.Empty, null);
decl.Value = reader.Value;
if(decl.Version != null && decl.Version != String.Empty) WriteAttributeString("version", decl.Version);
if(decl.Encoding != null && decl.Encoding != String.Empty) WriteAttributeString("encoding", decl.Encoding);
if(decl.Standalone != null && decl.Standalone != String.Empty) WriteAttributeString("standalone", decl.Standalone);
break;
case XmlNodeType.Element:
while (reader.MoveToNextAttribute ())
{
WriteAttributeString(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.Value);
}
break;
case XmlNodeType.Attribute:
do
{
WriteAttributeString(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.Value);
}
while (reader.MoveToNextAttribute ()) ;
break;
default:
throw new XmlException("NodeType is not one of Element, Attribute, nor XmlDeclaration.");
}
}
public void WriteAttributeString (string localName, string value)
{
WriteAttributeString ("", localName, "", value);
}
public void WriteAttributeString (string localName, string ns, string value)
{
WriteAttributeString ("", localName, ns, value);
}
public void WriteAttributeString (string prefix, string localName, string ns, string value)
{
if ((prefix == "xmlns") || (localName == "xmlns"))
{
ns = value;
if (prefix == "xmlns" && namespaceManager.HasNamespace (localName))
return;
/* Users need to be able to re-declare the default namespace for subnodes
else if (localName == "xmlns" && namespaceManager.HasNamespace (String.Empty))
return;
*/
}
WriteStartAttribute (prefix, localName, ns);
WriteString (value);
WriteEndAttribute ();
if ((prefix == "xmlns") || (localName == "xmlns"))
{
if (prefix == "xmlns")
namespaceManager.AddNamespace (localName, ns);
else
namespaceManager.AddNamespace ("", ns);
}
}
public abstract void WriteBase64 (byte[] buffer, int index, int count);
public abstract void WriteBinHex (byte[] buffer, int index, int count);
public abstract void WriteCData (string text);
public abstract void WriteCharEntity (char ch);
public abstract void WriteChars (char[] buffer, int index, int count);
public abstract void WriteComment (string text);
public abstract void WriteDocType (string name, string pubid, string sysid, string subset);
public void WriteElementString (string localName, string value)
{
WriteStartElement(localName);
WriteString(value);
WriteEndElement();
}
public void WriteElementString (string localName, string ns, string value)
{
WriteStartElement(localName, ns);
WriteString(value);
WriteEndElement();
}
public abstract void WriteEndAttribute ();
public abstract void WriteEndDocument ();
public abstract void WriteEndElement ();
public abstract void WriteEntityRef (string name);
public abstract void WriteFullEndElement ();
public abstract void WriteName (string name);
public abstract void WriteNmToken (string name);
[MonoTODO]
public virtual void WriteNode (XmlReader reader, bool defattr)
{
throw new NotImplementedException ();
}
public abstract void WriteProcessingInstruction (string name, string text);
public abstract void WriteQualifiedName (string localName, string ns);
public abstract void WriteRaw (string data);
public abstract void WriteRaw (char[] buffer, int index, int count);
public void WriteStartAttribute (string localName, string ns)
{
WriteStartAttribute ("", localName, ns);
}
public abstract void WriteStartAttribute (string prefix, string localName, string ns);
public abstract void WriteStartDocument ();
public abstract void WriteStartDocument (bool standalone);
public void WriteStartElement (string localName)
{
WriteStartElement (String.Empty, localName, String.Empty);
}
public void WriteStartElement (string localName, string ns)
{
WriteStartElement (String.Empty, localName, ns);
}
public abstract void WriteStartElement (string prefix, string localName, string ns);
public abstract void WriteString (string text);
public abstract void WriteSurrogateCharEntity (char lowChar, char highChar);
public abstract void WriteWhitespace (string ws);
#endregion
}
}
|