XmlWriterSettings.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // XmlWriterSettings.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C) 2004 Novell Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.IO;
  32. using System.Text;
  33. using System.Xml.Schema;
  34. namespace System.Xml
  35. {
  36. // FIXME: this class SHOULD have QuoteChar property
  37. // (feedback has done against Microsoft).
  38. public sealed class XmlWriterSettings : ICloneable
  39. {
  40. private bool checkCharacters;
  41. private bool closeOutput;
  42. private ConformanceLevel conformance;
  43. private Encoding encoding;
  44. private bool indent;
  45. private string indentChars;
  46. private string newLineChars;
  47. private bool newLineOnAttributes;
  48. private bool normalizeNewLines;
  49. private bool omitXmlDeclaration;
  50. public XmlWriterSettings ()
  51. {
  52. Reset ();
  53. }
  54. private XmlWriterSettings (XmlWriterSettings org)
  55. {
  56. checkCharacters = org.checkCharacters;
  57. closeOutput = org.closeOutput;
  58. conformance = org.conformance;
  59. encoding = org.encoding;
  60. indent = org.indent;
  61. indentChars = org.indentChars;
  62. newLineChars = org.newLineChars;
  63. newLineOnAttributes = org.newLineOnAttributes;
  64. normalizeNewLines = org.normalizeNewLines;
  65. omitXmlDeclaration = org.omitXmlDeclaration;
  66. }
  67. public XmlWriterSettings Clone ()
  68. {
  69. return new XmlWriterSettings (this);
  70. }
  71. object ICloneable.Clone ()
  72. {
  73. return this.Clone ();
  74. }
  75. public void Reset ()
  76. {
  77. checkCharacters = true;
  78. closeOutput = false; // ? not documented
  79. conformance = ConformanceLevel.Document;
  80. encoding = Encoding.UTF8;
  81. indent = false;
  82. indentChars = " ";
  83. // LAMESPEC: MS.NET says it is "\r\n", but it is silly decision.
  84. newLineChars = Environment.NewLine;
  85. newLineOnAttributes = false;
  86. normalizeNewLines = true;
  87. omitXmlDeclaration = false;
  88. }
  89. // It affects only on XmlTextWriter
  90. public bool CheckCharacters {
  91. get { return checkCharacters; }
  92. set { checkCharacters = value; }
  93. }
  94. // It affects only on XmlTextWriter
  95. public bool CloseOutput {
  96. get { return closeOutput; }
  97. set { closeOutput = value; }
  98. }
  99. // It affects only on XmlTextWriter????
  100. public ConformanceLevel ConformanceLevel {
  101. get { return conformance; }
  102. set { conformance = value; }
  103. }
  104. public Encoding Encoding {
  105. get { return encoding; }
  106. set { encoding = value; }
  107. }
  108. // It affects only on XmlTextWriter
  109. public bool Indent {
  110. get { return indent; }
  111. set { indent = value; }
  112. }
  113. // It affects only on XmlTextWriter
  114. public string IndentChars {
  115. get { return indentChars; }
  116. set { indentChars = value; }
  117. }
  118. // It affects only on XmlTextWriter
  119. public string NewLineChars {
  120. get { return newLineChars; }
  121. set { newLineChars = value; }
  122. }
  123. // It affects only on XmlTextWriter
  124. public bool NewLineOnAttributes {
  125. get { return newLineOnAttributes; }
  126. set { newLineOnAttributes = value; }
  127. }
  128. // It affects only on XmlTextWriter
  129. public bool NormalizeNewLines {
  130. get { return normalizeNewLines; }
  131. set { normalizeNewLines = value; }
  132. }
  133. // It affects only on XmlTextWriter
  134. public bool OmitXmlDeclaration {
  135. get { return omitXmlDeclaration; }
  136. set { omitXmlDeclaration = value; }
  137. }
  138. }
  139. }
  140. #endif