mscorlib(4.0.0.0) API with additions
XmlTextWriter.cs
4 using System.IO;
5 using System.Text;
6 
7 namespace System.Xml
8 {
10  [EditorBrowsable(EditorBrowsableState.Never)]
11  public class XmlTextWriter : XmlWriter
12  {
13  private enum NamespaceState
14  {
15  Uninitialized,
16  NotDeclaredButInScope,
17  DeclaredButNotWrittenOut,
18  DeclaredAndWrittenOut
19  }
20 
21  private struct TagInfo
22  {
23  internal string name;
24 
25  internal string prefix;
26 
27  internal string defaultNs;
28 
29  internal NamespaceState defaultNsState;
30 
31  internal XmlSpace xmlSpace;
32 
33  internal string xmlLang;
34 
35  internal int prevNsTop;
36 
37  internal int prefixCount;
38 
39  internal bool mixed;
40 
41  internal void Init(int nsTop)
42  {
43  name = null;
44  defaultNs = string.Empty;
45  defaultNsState = NamespaceState.Uninitialized;
46  xmlSpace = XmlSpace.None;
47  xmlLang = null;
48  prevNsTop = nsTop;
49  prefixCount = 0;
50  mixed = false;
51  }
52  }
53 
54  private struct Namespace
55  {
56  internal string prefix;
57 
58  internal string ns;
59 
60  internal bool declared;
61 
62  internal int prevNsIndex;
63 
64  internal void Set(string prefix, string ns, bool declared)
65  {
66  this.prefix = prefix;
67  this.ns = ns;
68  this.declared = declared;
69  prevNsIndex = -1;
70  }
71  }
72 
73  private enum SpecialAttr
74  {
75  None,
76  XmlSpace,
77  XmlLang,
78  XmlNs
79  }
80 
81  private enum State
82  {
83  Start,
84  Prolog,
85  PostDTD,
86  Element,
87  Attribute,
88  Content,
89  AttrOnly,
90  Epilog,
91  Error,
92  Closed
93  }
94 
95  private enum Token
96  {
97  PI,
98  Doctype,
99  Comment,
100  CData,
101  StartElement,
102  EndElement,
103  LongEndElement,
104  StartAttribute,
105  EndAttribute,
106  Content,
107  Base64,
108  RawData,
109  Whitespace,
110  Empty
111  }
112 
113  private TextWriter textWriter;
114 
115  private XmlTextEncoder xmlEncoder;
116 
117  private Encoding encoding;
118 
119  private Formatting formatting;
120 
121  private bool indented;
122 
123  private int indentation;
124 
125  private char indentChar;
126 
127  private TagInfo[] stack;
128 
129  private int top;
130 
131  private State[] stateTable;
132 
133  private State currentState;
134 
135  private Token lastToken;
136 
137  private XmlTextWriterBase64Encoder base64Encoder;
138 
139  private char quoteChar;
140 
141  private char curQuoteChar;
142 
143  private bool namespaces;
144 
145  private SpecialAttr specialAttr;
146 
147  private string prefixForXmlNs;
148 
149  private bool flush;
150 
151  private Namespace[] nsStack;
152 
153  private int nsTop;
154 
155  private Dictionary<string, int> nsHashtable;
156 
157  private bool useNsHashtable;
158 
159  private XmlCharType xmlCharType = XmlCharType.Instance;
160 
161  private const int NamespaceStackInitialSize = 8;
162 
163  private const int MaxNamespacesWalkCount = 16;
164 
165  private static string[] stateName = new string[10]
166  {
167  "Start",
168  "Prolog",
169  "PostDTD",
170  "Element",
171  "Attribute",
172  "Content",
173  "AttrOnly",
174  "Epilog",
175  "Error",
176  "Closed"
177  };
178 
179  private static string[] tokenName = new string[14]
180  {
181  "PI",
182  "Doctype",
183  "Comment",
184  "CData",
185  "StartElement",
186  "EndElement",
187  "LongEndElement",
188  "StartAttribute",
189  "EndAttribute",
190  "Content",
191  "Base64",
192  "RawData",
193  "Whitespace",
194  "Empty"
195  };
196 
197  private static readonly State[] stateTableDefault = new State[104]
198  {
199  State.Prolog,
200  State.Prolog,
201  State.PostDTD,
202  State.Content,
203  State.Content,
204  State.Content,
205  State.Error,
206  State.Epilog,
207  State.PostDTD,
208  State.PostDTD,
209  State.Error,
210  State.Error,
211  State.Error,
212  State.Error,
213  State.Error,
214  State.Error,
215  State.Prolog,
216  State.Prolog,
217  State.PostDTD,
218  State.Content,
219  State.Content,
220  State.Content,
221  State.Error,
222  State.Epilog,
223  State.Content,
224  State.Content,
225  State.Error,
226  State.Content,
227  State.Content,
228  State.Content,
229  State.Error,
230  State.Epilog,
231  State.Element,
232  State.Element,
233  State.Element,
234  State.Element,
235  State.Element,
236  State.Element,
237  State.Error,
238  State.Element,
239  State.Error,
240  State.Error,
241  State.Error,
242  State.Content,
243  State.Content,
244  State.Content,
245  State.Error,
246  State.Error,
247  State.Error,
248  State.Error,
249  State.Error,
250  State.Content,
251  State.Content,
252  State.Content,
253  State.Error,
254  State.Error,
255  State.AttrOnly,
256  State.Error,
257  State.Error,
258  State.Attribute,
259  State.Attribute,
260  State.Error,
261  State.Error,
262  State.Error,
263  State.Error,
264  State.Error,
265  State.Error,
266  State.Error,
267  State.Element,
268  State.Error,
269  State.Epilog,
270  State.Error,
271  State.Content,
272  State.Content,
273  State.Error,
274  State.Content,
275  State.Attribute,
276  State.Content,
277  State.Attribute,
278  State.Epilog,
279  State.Content,
280  State.Content,
281  State.Error,
282  State.Content,
283  State.Attribute,
284  State.Content,
285  State.Attribute,
286  State.Epilog,
287  State.Prolog,
288  State.Prolog,
289  State.PostDTD,
290  State.Content,
291  State.Attribute,
292  State.Content,
293  State.Attribute,
294  State.Epilog,
295  State.Prolog,
296  State.Prolog,
297  State.PostDTD,
298  State.Content,
299  State.Attribute,
300  State.Content,
301  State.Attribute,
302  State.Epilog
303  };
304 
305  private static readonly State[] stateTableDocument = new State[104]
306  {
307  State.Error,
308  State.Prolog,
309  State.PostDTD,
310  State.Content,
311  State.Content,
312  State.Content,
313  State.Error,
314  State.Epilog,
315  State.Error,
316  State.PostDTD,
317  State.Error,
318  State.Error,
319  State.Error,
320  State.Error,
321  State.Error,
322  State.Error,
323  State.Error,
324  State.Prolog,
325  State.PostDTD,
326  State.Content,
327  State.Content,
328  State.Content,
329  State.Error,
330  State.Epilog,
331  State.Error,
332  State.Error,
333  State.Error,
334  State.Content,
335  State.Content,
336  State.Content,
337  State.Error,
338  State.Error,
339  State.Error,
340  State.Element,
341  State.Element,
342  State.Element,
343  State.Element,
344  State.Element,
345  State.Error,
346  State.Error,
347  State.Error,
348  State.Error,
349  State.Error,
350  State.Content,
351  State.Content,
352  State.Content,
353  State.Error,
354  State.Error,
355  State.Error,
356  State.Error,
357  State.Error,
358  State.Content,
359  State.Content,
360  State.Content,
361  State.Error,
362  State.Error,
363  State.Error,
364  State.Error,
365  State.Error,
366  State.Attribute,
367  State.Attribute,
368  State.Error,
369  State.Error,
370  State.Error,
371  State.Error,
372  State.Error,
373  State.Error,
374  State.Error,
375  State.Element,
376  State.Error,
377  State.Error,
378  State.Error,
379  State.Error,
380  State.Error,
381  State.Error,
382  State.Content,
383  State.Attribute,
384  State.Content,
385  State.Error,
386  State.Error,
387  State.Error,
388  State.Error,
389  State.Error,
390  State.Content,
391  State.Attribute,
392  State.Content,
393  State.Error,
394  State.Error,
395  State.Error,
396  State.Prolog,
397  State.PostDTD,
398  State.Content,
399  State.Attribute,
400  State.Content,
401  State.Error,
402  State.Epilog,
403  State.Error,
404  State.Prolog,
405  State.PostDTD,
406  State.Content,
407  State.Attribute,
408  State.Content,
409  State.Error,
410  State.Epilog
411  };
412 
415  public Stream BaseStream => (textWriter as StreamWriter)?.BaseStream;
416 
421  public bool Namespaces
422  {
423  get
424  {
425  return namespaces;
426  }
427  set
428  {
429  if (currentState != 0)
430  {
431  throw new InvalidOperationException(Res.GetString("Xml_NotInWriteState"));
432  }
433  namespaces = value;
434  }
435  }
436 
439  public Formatting Formatting
440  {
441  get
442  {
443  return formatting;
444  }
445  set
446  {
447  formatting = value;
448  indented = (value == Formatting.Indented);
449  }
450  }
451 
455  public int Indentation
456  {
457  get
458  {
459  return indentation;
460  }
461  set
462  {
463  if (value < 0)
464  {
465  throw new ArgumentException(Res.GetString("Xml_InvalidIndentation"));
466  }
467  indentation = value;
468  }
469  }
470 
473  public char IndentChar
474  {
475  get
476  {
477  return indentChar;
478  }
479  set
480  {
481  indentChar = value;
482  }
483  }
484 
488  public char QuoteChar
489  {
490  get
491  {
492  return quoteChar;
493  }
494  set
495  {
496  if (value != '"' && value != '\'')
497  {
498  throw new ArgumentException(Res.GetString("Xml_InvalidQuote"));
499  }
500  quoteChar = value;
501  xmlEncoder.QuoteChar = value;
502  }
503  }
504 
507  public override WriteState WriteState
508  {
509  get
510  {
511  switch (currentState)
512  {
513  case State.Start:
514  return WriteState.Start;
515  case State.Prolog:
516  case State.PostDTD:
517  return WriteState.Prolog;
518  case State.Element:
519  return WriteState.Element;
520  case State.Attribute:
521  case State.AttrOnly:
522  return WriteState.Attribute;
523  case State.Content:
524  case State.Epilog:
525  return WriteState.Content;
526  case State.Error:
527  return WriteState.Error;
528  case State.Closed:
529  return WriteState.Closed;
530  default:
531  return WriteState.Error;
532  }
533  }
534  }
535 
538  public override XmlSpace XmlSpace
539  {
540  get
541  {
542  for (int num = top; num > 0; num--)
543  {
544  XmlSpace xmlSpace = stack[num].xmlSpace;
545  if (xmlSpace != 0)
546  {
547  return xmlSpace;
548  }
549  }
550  return XmlSpace.None;
551  }
552  }
553 
556  public override string XmlLang
557  {
558  get
559  {
560  for (int num = top; num > 0; num--)
561  {
562  string xmlLang = stack[num].xmlLang;
563  if (xmlLang != null)
564  {
565  return xmlLang;
566  }
567  }
568  return null;
569  }
570  }
571 
572  internal XmlTextWriter()
573  {
574  namespaces = true;
575  formatting = Formatting.None;
576  indentation = 2;
577  indentChar = ' ';
578  nsStack = new Namespace[8];
579  nsTop = -1;
580  stack = new TagInfo[10];
581  top = 0;
582  stack[top].Init(-1);
583  quoteChar = '"';
584  stateTable = stateTableDefault;
585  currentState = State.Start;
586  lastToken = Token.Empty;
587  }
588 
595  public XmlTextWriter(Stream w, Encoding encoding)
596  : this()
597  {
598  this.encoding = encoding;
599  if (encoding != null)
600  {
601  textWriter = new StreamWriter(w, encoding);
602  }
603  else
604  {
605  textWriter = new StreamWriter(w);
606  }
607  xmlEncoder = new XmlTextEncoder(textWriter);
608  xmlEncoder.QuoteChar = quoteChar;
609  }
610 
620  public XmlTextWriter(string filename, Encoding encoding)
621  : this(new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read), encoding)
622  {
623  }
624 
627  public XmlTextWriter(TextWriter w)
628  : this()
629  {
630  textWriter = w;
631  encoding = w.Encoding;
632  xmlEncoder = new XmlTextEncoder(w);
633  xmlEncoder.QuoteChar = quoteChar;
634  }
635 
638  public override void WriteStartDocument()
639  {
640  StartDocument(-1);
641  }
642 
646  public override void WriteStartDocument(bool standalone)
647  {
648  StartDocument(standalone ? 1 : 0);
649  }
650 
653  public override void WriteEndDocument()
654  {
655  try
656  {
657  AutoCompleteAll();
658  if (currentState != State.Epilog)
659  {
660  if (currentState == State.Closed)
661  {
662  throw new ArgumentException(Res.GetString("Xml_ClosedOrError"));
663  }
664  throw new ArgumentException(Res.GetString("Xml_NoRoot"));
665  }
666  stateTable = stateTableDefault;
667  currentState = State.Start;
668  lastToken = Token.Empty;
669  }
670  catch
671  {
672  currentState = State.Error;
673  throw;
674  }
675  }
676 
685  public override void WriteDocType(string name, string pubid, string sysid, string subset)
686  {
687  try
688  {
689  ValidateName(name, isNCName: false);
690  AutoComplete(Token.Doctype);
691  textWriter.Write("<!DOCTYPE ");
692  textWriter.Write(name);
693  if (pubid != null)
694  {
695  textWriter.Write(" PUBLIC " + quoteChar.ToString());
696  textWriter.Write(pubid);
697  textWriter.Write(quoteChar.ToString() + " " + quoteChar.ToString());
698  textWriter.Write(sysid);
699  textWriter.Write(quoteChar);
700  }
701  else if (sysid != null)
702  {
703  textWriter.Write(" SYSTEM " + quoteChar.ToString());
704  textWriter.Write(sysid);
705  textWriter.Write(quoteChar);
706  }
707  if (subset != null)
708  {
709  textWriter.Write("[");
710  textWriter.Write(subset);
711  textWriter.Write("]");
712  }
713  textWriter.Write('>');
714  }
715  catch
716  {
717  currentState = State.Error;
718  throw;
719  }
720  }
721 
727  public override void WriteStartElement(string prefix, string localName, string ns)
728  {
729  try
730  {
731  AutoComplete(Token.StartElement);
732  PushStack();
733  textWriter.Write('<');
734  if (namespaces)
735  {
736  stack[top].defaultNs = stack[top - 1].defaultNs;
737  if (stack[top - 1].defaultNsState != 0)
738  {
739  stack[top].defaultNsState = NamespaceState.NotDeclaredButInScope;
740  }
741  stack[top].mixed = stack[top - 1].mixed;
742  if (ns == null)
743  {
744  if (prefix != null && prefix.Length != 0 && LookupNamespace(prefix) == -1)
745  {
746  throw new ArgumentException(Res.GetString("Xml_UndefPrefix"));
747  }
748  }
749  else if (prefix == null)
750  {
751  string text = FindPrefix(ns);
752  if (text != null)
753  {
754  prefix = text;
755  }
756  else
757  {
758  PushNamespace(null, ns, declared: false);
759  }
760  }
761  else if (prefix.Length == 0)
762  {
763  PushNamespace(null, ns, declared: false);
764  }
765  else
766  {
767  if (ns.Length == 0)
768  {
769  prefix = null;
770  }
771  VerifyPrefixXml(prefix, ns);
772  PushNamespace(prefix, ns, declared: false);
773  }
774  stack[top].prefix = null;
775  if (prefix != null && prefix.Length != 0)
776  {
777  stack[top].prefix = prefix;
778  textWriter.Write(prefix);
779  textWriter.Write(':');
780  }
781  }
782  else if ((ns != null && ns.Length != 0) || (prefix != null && prefix.Length != 0))
783  {
784  throw new ArgumentException(Res.GetString("Xml_NoNamespaces"));
785  }
786  stack[top].name = localName;
787  textWriter.Write(localName);
788  }
789  catch
790  {
791  currentState = State.Error;
792  throw;
793  }
794  }
795 
797  public override void WriteEndElement()
798  {
799  InternalWriteEndElement(longFormat: false);
800  }
801 
803  public override void WriteFullEndElement()
804  {
805  InternalWriteEndElement(longFormat: true);
806  }
807 
817  public override void WriteStartAttribute(string prefix, string localName, string ns)
818  {
819  try
820  {
821  AutoComplete(Token.StartAttribute);
822  specialAttr = SpecialAttr.None;
823  if (namespaces)
824  {
825  if (prefix != null && prefix.Length == 0)
826  {
827  prefix = null;
828  }
829  if (ns == "http://www.w3.org/2000/xmlns/" && prefix == null && localName != "xmlns")
830  {
831  prefix = "xmlns";
832  }
833  if (prefix == "xml")
834  {
835  if (localName == "lang")
836  {
837  specialAttr = SpecialAttr.XmlLang;
838  }
839  else if (localName == "space")
840  {
841  specialAttr = SpecialAttr.XmlSpace;
842  }
843  }
844  else if (prefix == "xmlns")
845  {
846  if ("http://www.w3.org/2000/xmlns/" != ns && ns != null)
847  {
848  throw new ArgumentException(Res.GetString("Xml_XmlnsBelongsToReservedNs"));
849  }
850  if (localName == null || localName.Length == 0)
851  {
852  localName = prefix;
853  prefix = null;
854  prefixForXmlNs = null;
855  }
856  else
857  {
858  prefixForXmlNs = localName;
859  }
860  specialAttr = SpecialAttr.XmlNs;
861  }
862  else if (prefix == null && localName == "xmlns")
863  {
864  if ("http://www.w3.org/2000/xmlns/" != ns && ns != null)
865  {
866  throw new ArgumentException(Res.GetString("Xml_XmlnsBelongsToReservedNs"));
867  }
868  specialAttr = SpecialAttr.XmlNs;
869  prefixForXmlNs = null;
870  }
871  else if (ns == null)
872  {
873  if (prefix != null && LookupNamespace(prefix) == -1)
874  {
875  throw new ArgumentException(Res.GetString("Xml_UndefPrefix"));
876  }
877  }
878  else if (ns.Length == 0)
879  {
880  prefix = string.Empty;
881  }
882  else
883  {
884  VerifyPrefixXml(prefix, ns);
885  if (prefix != null && LookupNamespaceInCurrentScope(prefix) != -1)
886  {
887  prefix = null;
888  }
889  string text = FindPrefix(ns);
890  if (text != null && (prefix == null || prefix == text))
891  {
892  prefix = text;
893  }
894  else
895  {
896  if (prefix == null)
897  {
898  prefix = GeneratePrefix();
899  }
900  PushNamespace(prefix, ns, declared: false);
901  }
902  }
903  if (prefix != null && prefix.Length != 0)
904  {
905  textWriter.Write(prefix);
906  textWriter.Write(':');
907  }
908  }
909  else
910  {
911  if ((ns != null && ns.Length != 0) || (prefix != null && prefix.Length != 0))
912  {
913  throw new ArgumentException(Res.GetString("Xml_NoNamespaces"));
914  }
915  if (localName == "xml:lang")
916  {
917  specialAttr = SpecialAttr.XmlLang;
918  }
919  else if (localName == "xml:space")
920  {
921  specialAttr = SpecialAttr.XmlSpace;
922  }
923  }
924  xmlEncoder.StartAttribute(specialAttr != SpecialAttr.None);
925  textWriter.Write(localName);
926  textWriter.Write('=');
927  if (curQuoteChar != quoteChar)
928  {
929  curQuoteChar = quoteChar;
930  xmlEncoder.QuoteChar = quoteChar;
931  }
932  textWriter.Write(curQuoteChar);
933  }
934  catch
935  {
936  currentState = State.Error;
937  throw;
938  }
939  }
940 
942  public override void WriteEndAttribute()
943  {
944  try
945  {
946  AutoComplete(Token.EndAttribute);
947  }
948  catch
949  {
950  currentState = State.Error;
951  throw;
952  }
953  }
954 
959  public override void WriteCData(string text)
960  {
961  try
962  {
963  AutoComplete(Token.CData);
964  if (text != null && text.IndexOf("]]>", StringComparison.Ordinal) >= 0)
965  {
966  throw new ArgumentException(Res.GetString("Xml_InvalidCDataChars"));
967  }
968  textWriter.Write("<![CDATA[");
969  if (text != null)
970  {
971  xmlEncoder.WriteRawWithSurrogateChecking(text);
972  }
973  textWriter.Write("]]>");
974  }
975  catch
976  {
977  currentState = State.Error;
978  throw;
979  }
980  }
981 
986  public override void WriteComment(string text)
987  {
988  try
989  {
990  if (text != null && (text.IndexOf("--", StringComparison.Ordinal) >= 0 || (text.Length != 0 && text[text.Length - 1] == '-')))
991  {
992  throw new ArgumentException(Res.GetString("Xml_InvalidCommentChars"));
993  }
994  AutoComplete(Token.Comment);
995  textWriter.Write("<!--");
996  if (text != null)
997  {
998  xmlEncoder.WriteRawWithSurrogateChecking(text);
999  }
1000  textWriter.Write("-->");
1001  }
1002  catch
1003  {
1004  currentState = State.Error;
1005  throw;
1006  }
1007  }
1008 
1014  public override void WriteProcessingInstruction(string name, string text)
1015  {
1016  try
1017  {
1018  if (text != null && text.IndexOf("?>", StringComparison.Ordinal) >= 0)
1019  {
1020  throw new ArgumentException(Res.GetString("Xml_InvalidPiChars"));
1021  }
1022  if (string.Compare(name, "xml", StringComparison.OrdinalIgnoreCase) == 0 && stateTable == stateTableDocument)
1023  {
1024  throw new ArgumentException(Res.GetString("Xml_DupXmlDecl"));
1025  }
1026  AutoComplete(Token.PI);
1027  InternalWriteProcessingInstruction(name, text);
1028  }
1029  catch
1030  {
1031  currentState = State.Error;
1032  throw;
1033  }
1034  }
1035 
1039  public override void WriteEntityRef(string name)
1040  {
1041  try
1042  {
1043  ValidateName(name, isNCName: false);
1044  AutoComplete(Token.Content);
1045  xmlEncoder.WriteEntityRef(name);
1046  }
1047  catch
1048  {
1049  currentState = State.Error;
1050  throw;
1051  }
1052  }
1053 
1058  public override void WriteCharEntity(char ch)
1059  {
1060  try
1061  {
1062  AutoComplete(Token.Content);
1063  xmlEncoder.WriteCharEntity(ch);
1064  }
1065  catch
1066  {
1067  currentState = State.Error;
1068  throw;
1069  }
1070  }
1071 
1075  public override void WriteWhitespace(string ws)
1076  {
1077  try
1078  {
1079  if (ws == null)
1080  {
1081  ws = string.Empty;
1082  }
1083  if (!xmlCharType.IsOnlyWhitespace(ws))
1084  {
1085  throw new ArgumentException(Res.GetString("Xml_NonWhitespace"));
1086  }
1087  AutoComplete(Token.Whitespace);
1088  xmlEncoder.Write(ws);
1089  }
1090  catch
1091  {
1092  currentState = State.Error;
1093  throw;
1094  }
1095  }
1096 
1100  public override void WriteString(string text)
1101  {
1102  try
1103  {
1104  if (text != null && text.Length != 0)
1105  {
1106  AutoComplete(Token.Content);
1107  xmlEncoder.Write(text);
1108  }
1109  }
1110  catch
1111  {
1112  currentState = State.Error;
1113  throw;
1114  }
1115  }
1116 
1121  public override void WriteSurrogateCharEntity(char lowChar, char highChar)
1122  {
1123  try
1124  {
1125  AutoComplete(Token.Content);
1126  xmlEncoder.WriteSurrogateCharEntity(lowChar, highChar);
1127  }
1128  catch
1129  {
1130  currentState = State.Error;
1131  throw;
1132  }
1133  }
1134 
1144  public override void WriteChars(char[] buffer, int index, int count)
1145  {
1146  try
1147  {
1148  AutoComplete(Token.Content);
1149  xmlEncoder.Write(buffer, index, count);
1150  }
1151  catch
1152  {
1153  currentState = State.Error;
1154  throw;
1155  }
1156  }
1157 
1166  public override void WriteRaw(char[] buffer, int index, int count)
1167  {
1168  try
1169  {
1170  AutoComplete(Token.RawData);
1171  xmlEncoder.WriteRaw(buffer, index, count);
1172  }
1173  catch
1174  {
1175  currentState = State.Error;
1176  throw;
1177  }
1178  }
1179 
1182  public override void WriteRaw(string data)
1183  {
1184  try
1185  {
1186  AutoComplete(Token.RawData);
1187  xmlEncoder.WriteRawWithSurrogateChecking(data);
1188  }
1189  catch
1190  {
1191  currentState = State.Error;
1192  throw;
1193  }
1194  }
1195 
1206  public override void WriteBase64(byte[] buffer, int index, int count)
1207  {
1208  try
1209  {
1210  if (!flush)
1211  {
1212  AutoComplete(Token.Base64);
1213  }
1214  flush = true;
1215  if (base64Encoder == null)
1216  {
1217  base64Encoder = new XmlTextWriterBase64Encoder(xmlEncoder);
1218  }
1219  base64Encoder.Encode(buffer, index, count);
1220  }
1221  catch
1222  {
1223  currentState = State.Error;
1224  throw;
1225  }
1226  }
1227 
1238  public override void WriteBinHex(byte[] buffer, int index, int count)
1239  {
1240  try
1241  {
1242  AutoComplete(Token.Content);
1243  BinHexEncoder.Encode(buffer, index, count, this);
1244  }
1245  catch
1246  {
1247  currentState = State.Error;
1248  throw;
1249  }
1250  }
1251 
1253  public override void Close()
1254  {
1255  try
1256  {
1257  AutoCompleteAll();
1258  }
1259  catch
1260  {
1261  }
1262  finally
1263  {
1264  currentState = State.Closed;
1265  textWriter.Close();
1266  }
1267  }
1268 
1270  public override void Flush()
1271  {
1272  textWriter.Flush();
1273  }
1274 
1279  public override void WriteName(string name)
1280  {
1281  try
1282  {
1283  AutoComplete(Token.Content);
1284  InternalWriteName(name, isNCName: false);
1285  }
1286  catch
1287  {
1288  currentState = State.Error;
1289  throw;
1290  }
1291  }
1292 
1299  public override void WriteQualifiedName(string localName, string ns)
1300  {
1301  try
1302  {
1303  AutoComplete(Token.Content);
1304  if (namespaces)
1305  {
1306  if (ns != null && ns.Length != 0 && ns != stack[top].defaultNs)
1307  {
1308  string text = FindPrefix(ns);
1309  if (text == null)
1310  {
1311  if (currentState != State.Attribute)
1312  {
1313  throw new ArgumentException(Res.GetString("Xml_UndefNamespace", ns));
1314  }
1315  text = GeneratePrefix();
1316  PushNamespace(text, ns, declared: false);
1317  }
1318  if (text.Length != 0)
1319  {
1320  InternalWriteName(text, isNCName: true);
1321  textWriter.Write(':');
1322  }
1323  }
1324  }
1325  else if (ns != null && ns.Length != 0)
1326  {
1327  throw new ArgumentException(Res.GetString("Xml_NoNamespaces"));
1328  }
1329  InternalWriteName(localName, isNCName: true);
1330  }
1331  catch
1332  {
1333  currentState = State.Error;
1334  throw;
1335  }
1336  }
1337 
1343  public override string LookupPrefix(string ns)
1344  {
1345  if (ns == null || ns.Length == 0)
1346  {
1347  throw new ArgumentException(Res.GetString("Xml_EmptyName"));
1348  }
1349  string text = FindPrefix(ns);
1350  if (text == null && ns == stack[top].defaultNs)
1351  {
1352  text = string.Empty;
1353  }
1354  return text;
1355  }
1356 
1361  public override void WriteNmToken(string name)
1362  {
1363  try
1364  {
1365  AutoComplete(Token.Content);
1366  if (name == null || name.Length == 0)
1367  {
1368  throw new ArgumentException(Res.GetString("Xml_EmptyName"));
1369  }
1370  if (!ValidateNames.IsNmtokenNoNamespaces(name))
1371  {
1372  throw new ArgumentException(Res.GetString("Xml_InvalidNameChars", name));
1373  }
1374  textWriter.Write(name);
1375  }
1376  catch
1377  {
1378  currentState = State.Error;
1379  throw;
1380  }
1381  }
1382 
1383  private void StartDocument(int standalone)
1384  {
1385  try
1386  {
1387  if (currentState != 0)
1388  {
1389  throw new InvalidOperationException(Res.GetString("Xml_NotTheFirst"));
1390  }
1391  stateTable = stateTableDocument;
1392  currentState = State.Prolog;
1393  StringBuilder stringBuilder = new StringBuilder(128);
1394  stringBuilder.Append("version=" + quoteChar.ToString() + "1.0" + quoteChar.ToString());
1395  if (encoding != null)
1396  {
1397  stringBuilder.Append(" encoding=");
1398  stringBuilder.Append(quoteChar);
1399  stringBuilder.Append(encoding.WebName);
1400  stringBuilder.Append(quoteChar);
1401  }
1402  if (standalone >= 0)
1403  {
1404  stringBuilder.Append(" standalone=");
1405  stringBuilder.Append(quoteChar);
1406  stringBuilder.Append((standalone == 0) ? "no" : "yes");
1407  stringBuilder.Append(quoteChar);
1408  }
1409  InternalWriteProcessingInstruction("xml", stringBuilder.ToString());
1410  }
1411  catch
1412  {
1413  currentState = State.Error;
1414  throw;
1415  }
1416  }
1417 
1418  private void AutoComplete(Token token)
1419  {
1420  if (currentState == State.Closed)
1421  {
1422  throw new InvalidOperationException(Res.GetString("Xml_Closed"));
1423  }
1424  if (currentState == State.Error)
1425  {
1426  throw new InvalidOperationException(Res.GetString("Xml_WrongToken", tokenName[(int)token], stateName[8]));
1427  }
1428  State state = stateTable[(int)((int)token * 8 + currentState)];
1429  if (state == State.Error)
1430  {
1431  throw new InvalidOperationException(Res.GetString("Xml_WrongToken", tokenName[(int)token], stateName[(int)currentState]));
1432  }
1433  switch (token)
1434  {
1435  case Token.Doctype:
1436  if (indented && currentState != 0)
1437  {
1438  Indent(beforeEndElement: false);
1439  }
1440  break;
1441  case Token.PI:
1442  case Token.Comment:
1443  case Token.CData:
1444  case Token.StartElement:
1445  if (currentState == State.Attribute)
1446  {
1447  WriteEndAttributeQuote();
1448  WriteEndStartTag(empty: false);
1449  }
1450  else if (currentState == State.Element)
1451  {
1452  WriteEndStartTag(empty: false);
1453  }
1454  if (token == Token.CData)
1455  {
1456  stack[top].mixed = true;
1457  }
1458  else if (indented && currentState != 0)
1459  {
1460  Indent(beforeEndElement: false);
1461  }
1462  break;
1463  case Token.EndElement:
1464  case Token.LongEndElement:
1465  if (flush)
1466  {
1467  FlushEncoders();
1468  }
1469  if (currentState == State.Attribute)
1470  {
1471  WriteEndAttributeQuote();
1472  }
1473  if (currentState == State.Content)
1474  {
1475  token = Token.LongEndElement;
1476  }
1477  else
1478  {
1479  WriteEndStartTag(token == Token.EndElement);
1480  }
1481  if (stateTableDocument == stateTable && top == 1)
1482  {
1483  state = State.Epilog;
1484  }
1485  break;
1486  case Token.StartAttribute:
1487  if (flush)
1488  {
1489  FlushEncoders();
1490  }
1491  if (currentState == State.Attribute)
1492  {
1493  WriteEndAttributeQuote();
1494  textWriter.Write(' ');
1495  }
1496  else if (currentState == State.Element)
1497  {
1498  textWriter.Write(' ');
1499  }
1500  break;
1501  case Token.EndAttribute:
1502  if (flush)
1503  {
1504  FlushEncoders();
1505  }
1506  WriteEndAttributeQuote();
1507  break;
1508  case Token.Content:
1509  case Token.RawData:
1510  case Token.Whitespace:
1511  if (flush)
1512  {
1513  FlushEncoders();
1514  }
1515  goto case Token.Base64;
1516  case Token.Base64:
1517  if (currentState == State.Element && lastToken != Token.Content)
1518  {
1519  WriteEndStartTag(empty: false);
1520  }
1521  if (state == State.Content)
1522  {
1523  stack[top].mixed = true;
1524  }
1525  break;
1526  default:
1527  throw new InvalidOperationException(Res.GetString("Xml_InvalidOperation"));
1528  }
1529  currentState = state;
1530  lastToken = token;
1531  }
1532 
1533  private void AutoCompleteAll()
1534  {
1535  if (flush)
1536  {
1537  FlushEncoders();
1538  }
1539  while (top > 0)
1540  {
1541  WriteEndElement();
1542  }
1543  }
1544 
1545  private void InternalWriteEndElement(bool longFormat)
1546  {
1547  try
1548  {
1549  if (top <= 0)
1550  {
1551  throw new InvalidOperationException(Res.GetString("Xml_NoStartTag"));
1552  }
1553  AutoComplete(longFormat ? Token.LongEndElement : Token.EndElement);
1554  if (lastToken == Token.LongEndElement)
1555  {
1556  if (indented)
1557  {
1558  Indent(beforeEndElement: true);
1559  }
1560  textWriter.Write('<');
1561  textWriter.Write('/');
1562  if (namespaces && stack[top].prefix != null)
1563  {
1564  textWriter.Write(stack[top].prefix);
1565  textWriter.Write(':');
1566  }
1567  textWriter.Write(stack[top].name);
1568  textWriter.Write('>');
1569  }
1570  int prevNsTop = stack[top].prevNsTop;
1571  if (useNsHashtable && prevNsTop < nsTop)
1572  {
1573  PopNamespaces(prevNsTop + 1, nsTop);
1574  }
1575  nsTop = prevNsTop;
1576  top--;
1577  }
1578  catch
1579  {
1580  currentState = State.Error;
1581  throw;
1582  }
1583  }
1584 
1585  private void WriteEndStartTag(bool empty)
1586  {
1587  xmlEncoder.StartAttribute(cacheAttrValue: false);
1588  for (int num = nsTop; num > stack[top].prevNsTop; num--)
1589  {
1590  if (!nsStack[num].declared)
1591  {
1592  textWriter.Write(" xmlns");
1593  textWriter.Write(':');
1594  textWriter.Write(nsStack[num].prefix);
1595  textWriter.Write('=');
1596  textWriter.Write(quoteChar);
1597  xmlEncoder.Write(nsStack[num].ns);
1598  textWriter.Write(quoteChar);
1599  }
1600  }
1601  if (stack[top].defaultNs != stack[top - 1].defaultNs && stack[top].defaultNsState == NamespaceState.DeclaredButNotWrittenOut)
1602  {
1603  textWriter.Write(" xmlns");
1604  textWriter.Write('=');
1605  textWriter.Write(quoteChar);
1606  xmlEncoder.Write(stack[top].defaultNs);
1607  textWriter.Write(quoteChar);
1608  stack[top].defaultNsState = NamespaceState.DeclaredAndWrittenOut;
1609  }
1610  xmlEncoder.EndAttribute();
1611  if (empty)
1612  {
1613  textWriter.Write(" /");
1614  }
1615  textWriter.Write('>');
1616  }
1617 
1618  private void WriteEndAttributeQuote()
1619  {
1620  if (specialAttr != 0)
1621  {
1622  HandleSpecialAttribute();
1623  }
1624  xmlEncoder.EndAttribute();
1625  textWriter.Write(curQuoteChar);
1626  }
1627 
1628  private void Indent(bool beforeEndElement)
1629  {
1630  if (top == 0)
1631  {
1632  textWriter.WriteLine();
1633  }
1634  else if (!stack[top].mixed)
1635  {
1636  textWriter.WriteLine();
1637  int num = beforeEndElement ? (top - 1) : top;
1638  for (num *= indentation; num > 0; num--)
1639  {
1640  textWriter.Write(indentChar);
1641  }
1642  }
1643  }
1644 
1645  private void PushNamespace(string prefix, string ns, bool declared)
1646  {
1647  if ("http://www.w3.org/2000/xmlns/" == ns)
1648  {
1649  throw new ArgumentException(Res.GetString("Xml_CanNotBindToReservedNamespace"));
1650  }
1651  if (prefix == null)
1652  {
1653  switch (stack[top].defaultNsState)
1654  {
1655  default:
1656  return;
1657  case NamespaceState.Uninitialized:
1658  case NamespaceState.NotDeclaredButInScope:
1659  stack[top].defaultNs = ns;
1660  break;
1661  case NamespaceState.DeclaredButNotWrittenOut:
1662  break;
1663  }
1664  stack[top].defaultNsState = (declared ? NamespaceState.DeclaredAndWrittenOut : NamespaceState.DeclaredButNotWrittenOut);
1665  return;
1666  }
1667  if (prefix.Length != 0 && ns.Length == 0)
1668  {
1669  throw new ArgumentException(Res.GetString("Xml_PrefixForEmptyNs"));
1670  }
1671  int num = LookupNamespace(prefix);
1672  if (num != -1 && nsStack[num].ns == ns)
1673  {
1674  if (declared)
1675  {
1676  nsStack[num].declared = true;
1677  }
1678  return;
1679  }
1680  if (declared && num != -1 && num > stack[top].prevNsTop)
1681  {
1682  nsStack[num].declared = true;
1683  }
1684  AddNamespace(prefix, ns, declared);
1685  }
1686 
1687  private void AddNamespace(string prefix, string ns, bool declared)
1688  {
1689  int num = ++nsTop;
1690  if (num == nsStack.Length)
1691  {
1692  Namespace[] destinationArray = new Namespace[num * 2];
1693  Array.Copy(nsStack, destinationArray, num);
1694  nsStack = destinationArray;
1695  }
1696  nsStack[num].Set(prefix, ns, declared);
1697  if (useNsHashtable)
1698  {
1699  AddToNamespaceHashtable(num);
1700  }
1701  else if (num == 16)
1702  {
1703  nsHashtable = new Dictionary<string, int>(new SecureStringHasher());
1704  for (int i = 0; i <= num; i++)
1705  {
1706  AddToNamespaceHashtable(i);
1707  }
1708  useNsHashtable = true;
1709  }
1710  }
1711 
1712  private void AddToNamespaceHashtable(int namespaceIndex)
1713  {
1714  string prefix = nsStack[namespaceIndex].prefix;
1715  if (nsHashtable.TryGetValue(prefix, out int value))
1716  {
1717  nsStack[namespaceIndex].prevNsIndex = value;
1718  }
1719  nsHashtable[prefix] = namespaceIndex;
1720  }
1721 
1722  private void PopNamespaces(int indexFrom, int indexTo)
1723  {
1724  for (int num = indexTo; num >= indexFrom; num--)
1725  {
1726  if (nsStack[num].prevNsIndex == -1)
1727  {
1728  nsHashtable.Remove(nsStack[num].prefix);
1729  }
1730  else
1731  {
1732  nsHashtable[nsStack[num].prefix] = nsStack[num].prevNsIndex;
1733  }
1734  }
1735  }
1736 
1737  private string GeneratePrefix()
1738  {
1739  int num = stack[top].prefixCount++;
1740  return "d" + top.ToString("d", CultureInfo.InvariantCulture) + "p" + (num + 1).ToString("d", CultureInfo.InvariantCulture);
1741  }
1742 
1743  private void InternalWriteProcessingInstruction(string name, string text)
1744  {
1745  textWriter.Write("<?");
1746  ValidateName(name, isNCName: false);
1747  textWriter.Write(name);
1748  textWriter.Write(' ');
1749  if (text != null)
1750  {
1751  xmlEncoder.WriteRawWithSurrogateChecking(text);
1752  }
1753  textWriter.Write("?>");
1754  }
1755 
1756  private int LookupNamespace(string prefix)
1757  {
1758  if (useNsHashtable)
1759  {
1760  if (nsHashtable.TryGetValue(prefix, out int value))
1761  {
1762  return value;
1763  }
1764  }
1765  else
1766  {
1767  for (int num = nsTop; num >= 0; num--)
1768  {
1769  if (nsStack[num].prefix == prefix)
1770  {
1771  return num;
1772  }
1773  }
1774  }
1775  return -1;
1776  }
1777 
1778  private int LookupNamespaceInCurrentScope(string prefix)
1779  {
1780  if (useNsHashtable)
1781  {
1782  if (nsHashtable.TryGetValue(prefix, out int value) && value > stack[top].prevNsTop)
1783  {
1784  return value;
1785  }
1786  }
1787  else
1788  {
1789  for (int num = nsTop; num > stack[top].prevNsTop; num--)
1790  {
1791  if (nsStack[num].prefix == prefix)
1792  {
1793  return num;
1794  }
1795  }
1796  }
1797  return -1;
1798  }
1799 
1800  private string FindPrefix(string ns)
1801  {
1802  for (int num = nsTop; num >= 0; num--)
1803  {
1804  if (nsStack[num].ns == ns && LookupNamespace(nsStack[num].prefix) == num)
1805  {
1806  return nsStack[num].prefix;
1807  }
1808  }
1809  return null;
1810  }
1811 
1812  private void InternalWriteName(string name, bool isNCName)
1813  {
1814  ValidateName(name, isNCName);
1815  textWriter.Write(name);
1816  }
1817 
1818  private void ValidateName(string name, bool isNCName)
1819  {
1820  if (name == null || name.Length == 0)
1821  {
1822  throw new ArgumentException(Res.GetString("Xml_EmptyName"));
1823  }
1824  int length = name.Length;
1825  if (namespaces)
1826  {
1827  int num = -1;
1828  int num2 = ValidateNames.ParseNCName(name);
1829  while (true)
1830  {
1831  if (num2 == length)
1832  {
1833  return;
1834  }
1835  if (name[num2] != ':' || isNCName || num != -1 || num2 <= 0 || num2 + 1 >= length)
1836  {
1837  break;
1838  }
1839  num = num2;
1840  num2++;
1841  num2 += ValidateNames.ParseNmtoken(name, num2);
1842  }
1843  }
1844  else if (ValidateNames.IsNameNoNamespaces(name))
1845  {
1846  return;
1847  }
1848  throw new ArgumentException(Res.GetString("Xml_InvalidNameChars", name));
1849  }
1850 
1851  private void HandleSpecialAttribute()
1852  {
1853  string attributeValue = xmlEncoder.AttributeValue;
1854  switch (specialAttr)
1855  {
1856  case SpecialAttr.XmlLang:
1857  stack[top].xmlLang = attributeValue;
1858  break;
1859  case SpecialAttr.XmlSpace:
1860  attributeValue = XmlConvert.TrimString(attributeValue);
1861  if (attributeValue == "default")
1862  {
1863  stack[top].xmlSpace = XmlSpace.Default;
1864  break;
1865  }
1866  if (attributeValue == "preserve")
1867  {
1868  stack[top].xmlSpace = XmlSpace.Preserve;
1869  break;
1870  }
1871  throw new ArgumentException(Res.GetString("Xml_InvalidXmlSpace", attributeValue));
1872  case SpecialAttr.XmlNs:
1873  VerifyPrefixXml(prefixForXmlNs, attributeValue);
1874  PushNamespace(prefixForXmlNs, attributeValue, declared: true);
1875  break;
1876  }
1877  }
1878 
1879  private void VerifyPrefixXml(string prefix, string ns)
1880  {
1881  if (prefix != null && prefix.Length == 3 && (prefix[0] == 'x' || prefix[0] == 'X') && (prefix[1] == 'm' || prefix[1] == 'M') && (prefix[2] == 'l' || prefix[2] == 'L') && "http://www.w3.org/XML/1998/namespace" != ns)
1882  {
1883  throw new ArgumentException(Res.GetString("Xml_InvalidPrefix"));
1884  }
1885  }
1886 
1887  private void PushStack()
1888  {
1889  if (top == stack.Length - 1)
1890  {
1891  TagInfo[] destinationArray = new TagInfo[stack.Length + 10];
1892  if (top > 0)
1893  {
1894  Array.Copy(stack, destinationArray, top + 1);
1895  }
1896  stack = destinationArray;
1897  }
1898  top++;
1899  stack[top].Init(nsTop);
1900  }
1901 
1902  private void FlushEncoders()
1903  {
1904  if (base64Encoder != null)
1905  {
1906  base64Encoder.Flush();
1907  }
1908  flush = false;
1909  }
1910  }
1911 }
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
abstract void WriteBase64(byte[] buffer, int index, int count)
When overridden in a derived class, encodes the specified binary bytes as Base64 and writes out the r...
Indicates that the prolog is being written.
abstract void WriteChars(char[] buffer, int index, int count)
When overridden in a derived class, writes text one buffer at a time.
int Indentation
Gets or sets how many IndentChars to write for each level in the hierarchy when P:System....
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
virtual void WriteBinHex(byte[] buffer, int index, int count)
When overridden in a derived class, encodes the specified binary bytes as BinHex and writes out the r...
Definition: XmlWriter.cs:345
static XmlWriter Create(string outputFileName)
Creates a new T:System.Xml.XmlWriter instance using the specified filename.
Definition: XmlWriter.cs:854
abstract void WriteStartDocument()
When overridden in a derived class, writes the XML declaration with the version "1....
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
The T:System.Diagnostics.EventLog can write to existing logs, and create event sources and logs.
FileMode
Specifies how the operating system should open a file.
Definition: FileMode.cs:8
EditorBrowsableState
Specifies the browsable state of a property or method from within an editor.
Represents the base class for custom attributes.
Definition: Attribute.cs:15
Definition: __Canon.cs:3
The T:System.Diagnostics.PerformanceCounter can read categories.
abstract void WriteEndAttribute()
When overridden in a derived class, closes the previous M:System.Xml.XmlWriter.WriteStartAttribute(Sy...
void WriteStartAttribute(string localName, string ns)
Writes the start of an attribute with the specified local name and namespace URI.
Definition: XmlWriter.cs:199
abstract void WriteWhitespace(string ws)
When overridden in a derived class, writes out the given white space.
virtual void WriteQualifiedName(string localName, string ns)
When overridden in a derived class, writes out the namespace-qualified name. This method looks up the...
Definition: XmlWriter.cs:405
The code generator produces code for the contents of the object, rather than for the object itself.
abstract void WriteString(string text)
When overridden in a derived class, writes the given text content.
virtual string XmlLang
When overridden in a derived class, gets the current xml:lang scope.
Definition: XmlWriter.cs:65
abstract void WriteEndDocument()
When overridden in a derived class, closes any open elements or attributes and puts the writer back i...
abstract string LookupPrefix(string ns)
When overridden in a derived class, returns the closest prefix defined in the current namespace scope...
Represents a writer that provides a fast, non-cached, forward-only way to generate streams or files t...
Definition: XmlWriter.cs:12
virtual void WriteNmToken(string name)
When overridden in a derived class, writes out the specified name, ensuring it is a valid NmToken acc...
Definition: XmlWriter.cs:377
abstract void Flush()
When overridden in a derived class, flushes whatever is in the buffer to the underlying streams and a...
Implements a T:System.IO.TextWriter for writing characters to a stream in a particular encoding....
Definition: StreamWriter.cs:15
abstract Encoding Encoding
When overridden in a derived class, returns the character encoding in which the output is written.
Definition: TextWriter.cs:449
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
virtual string WebName
When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Autho...
Definition: Encoding.cs:750
abstract void WriteFullEndElement()
When overridden in a derived class, closes one element and pops the corresponding namespace scope.
virtual XmlSpace XmlSpace
When overridden in a derived class, gets an T:System.Xml.XmlSpace representing the current xml:space ...
Definition: XmlWriter.cs:52
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
Definition: FileStream.cs:15
Represents a writer that provides a fast, non-cached, forward-only way of generating streams or files...
abstract void WriteCharEntity(char ch)
When overridden in a derived class, forces the generation of a character entity for the specified Uni...
Represents a writer that can write a sequential series of characters. This class is abstract.
Definition: TextWriter.cs:15
abstract void WriteCData(string text)
When overridden in a derived class, writes out a <![CDATA[...]]> block containing the specified text.
An end element tag (for example, </item> ).
abstract void WriteDocType(string name, string pubid, string sysid, string subset)
When overridden in a derived class, writes the DOCTYPE declaration with the specified name and option...
abstract void WriteEndElement()
When overridden in a derived class, closes one element and pops the corresponding namespace scope.
virtual void Flush()
Clears all buffers for the current writer and causes any buffered data to be written to the underlyin...
Definition: TextWriter.cs:515
char IndentChar
Gets or sets which character to use for indenting when P:System.Xml.XmlTextWriter....
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
abstract void WriteSurrogateCharEntity(char lowChar, char highChar)
When overridden in a derived class, generates and writes the surrogate character entity for the surro...
Formatting Formatting
Indicates how the output is formatted.
abstract void WriteEntityRef(string name)
When overridden in a derived class, writes out an entity reference as &name;.
abstract void WriteRaw(char[] buffer, int index, int count)
When overridden in a derived class, writes raw markup manually from a character buffer.
The exception that is thrown when one of the arguments provided to a method is not valid.
virtual void Close()
When overridden in a derived class, closes this stream and the underlying stream.
Definition: XmlWriter.cs:353
This value supports the .NET Framework infrastructure and is not intended to be used directly from yo...
FileAccess
Defines constants for read, write, or read/write access to a file.
Definition: FileAccess.cs:9
abstract void WriteComment(string text)
When overridden in a derived class, writes out a comment <!–...–> containing the specified text.
bool Namespaces
Gets or sets a value indicating whether to do namespace support.
virtual void WriteLine()
Writes a line terminator to the text string or stream.
Definition: TextWriter.cs:778
virtual void Close()
Closes the current writer and releases any system resources associated with the writer.
Definition: TextWriter.cs:491
Formatting
Specifies formatting options for the T:System.Xml.XmlTextWriter.
Definition: Formatting.cs:4
The exception that is thrown when a method call is invalid for the object's current state.
abstract void WriteProcessingInstruction(string name, string text)
When overridden in a derived class, writes out a processing instruction with a space between the name...
XmlSpace
Specifies the current xml:space scope.
Definition: XmlSpace.cs:5
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
virtual void Write(char value)
Writes a character to the text string or stream.
Definition: TextWriter.cs:543
Stream BaseStream
Gets the underlying stream object.
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
Definition: Dictionary.cs:1624
abstract WriteState WriteState
When overridden in a derived class, gets the state of the writer.
Definition: XmlWriter.cs:36
virtual void WriteName(string name)
When overridden in a derived class, writes out the specified name, ensuring it is a valid name accord...
Definition: XmlWriter.cs:392
FileShare
Contains constants for controlling the kind of access other T:System.IO.FileStream objects can have t...
Definition: FileShare.cs:9
void WriteStartElement(string localName, string ns)
When overridden in a derived class, writes the specified start tag and associates it with the given n...
Definition: XmlWriter.cs:110
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
Definition: Stream.cs:16