XmlTextWriter.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. //
  2. // System.Xml.XmlTextWriter
  3. //
  4. // Author:
  5. // Kral Ferch <[email protected]>
  6. //
  7. // (C) 2002 Kral Ferch
  8. //
  9. // [FIXME]
  10. // Document state should be considered.
  11. //
  12. using System;
  13. using System.Collections;
  14. using System.IO;
  15. using System.Text;
  16. namespace System.Xml
  17. {
  18. public class XmlTextWriter : XmlWriter
  19. {
  20. #region Fields
  21. TextWriter w;
  22. bool nullEncoding = false;
  23. bool openWriter = true;
  24. bool openStartElement = false;
  25. bool openStartAttribute = false;
  26. bool documentStarted = false;
  27. bool namespaces = true;
  28. bool openAttribute = false;
  29. bool attributeWrittenForElement = false;
  30. Stack openElements = new Stack ();
  31. Formatting formatting = Formatting.None;
  32. int indentation = 2;
  33. char indentChar = ' ';
  34. string indentChars = " ";
  35. char quoteChar = '\"';
  36. int indentLevel = 0;
  37. string indentFormatting;
  38. Stream baseStream = null;
  39. string xmlLang = null;
  40. XmlSpace xmlSpace = XmlSpace.None;
  41. bool openXmlLang = false;
  42. bool openXmlSpace = false;
  43. string openElementPrefix;
  44. string openElementNS;
  45. bool openElementNsAdded;
  46. bool hasRoot = false;
  47. Hashtable writtenAttributes = new Hashtable ();
  48. ArrayList newAttributeNamespaces = new ArrayList ();
  49. bool checkMultipleAttributes = false;
  50. #endregion
  51. #region Constructors
  52. public XmlTextWriter (TextWriter w) : base ()
  53. {
  54. this.w = w;
  55. nullEncoding = (w.Encoding == null);
  56. try {
  57. baseStream = ((StreamWriter)w).BaseStream;
  58. }
  59. catch (Exception) { }
  60. }
  61. public XmlTextWriter (Stream w, Encoding encoding) : base ()
  62. {
  63. if (encoding == null) {
  64. nullEncoding = true;
  65. encoding = new UTF8Encoding ();
  66. }
  67. this.w = new StreamWriter(w, encoding);
  68. baseStream = w;
  69. }
  70. public XmlTextWriter (string filename, Encoding encoding) :
  71. this (new FileStream (filename, FileMode.Create, FileAccess.Write, FileShare.None), encoding)
  72. {
  73. }
  74. #endregion
  75. #region Properties
  76. public Stream BaseStream {
  77. get { return baseStream; }
  78. }
  79. public Formatting Formatting {
  80. get { return formatting; }
  81. set { formatting = value; }
  82. }
  83. private bool IndentingOverriden
  84. {
  85. get {
  86. if (openElements.Count == 0)
  87. return false;
  88. else
  89. return (((XmlTextWriterOpenElement)openElements.Peek()).IndentingOverriden);
  90. }
  91. set {
  92. if (openElements.Count > 0)
  93. ((XmlTextWriterOpenElement)openElements.Peek()).IndentingOverriden = value;
  94. }
  95. }
  96. public int Indentation {
  97. get { return indentation; }
  98. set {
  99. indentation = value;
  100. UpdateIndentChars ();
  101. }
  102. }
  103. public char IndentChar {
  104. get { return indentChar; }
  105. set {
  106. indentChar = value;
  107. UpdateIndentChars ();
  108. }
  109. }
  110. public bool Namespaces {
  111. get { return namespaces; }
  112. set {
  113. if (ws != WriteState.Start)
  114. throw new InvalidOperationException ("NotInWriteState.");
  115. namespaces = value;
  116. }
  117. }
  118. public char QuoteChar {
  119. get { return quoteChar; }
  120. set {
  121. if ((value != '\'') && (value != '\"'))
  122. throw new ArgumentException ("This is an invalid XML attribute quote character. Valid attribute quote characters are ' and \".");
  123. quoteChar = value;
  124. }
  125. }
  126. public override WriteState WriteState {
  127. get { return ws; }
  128. }
  129. public override string XmlLang {
  130. get {
  131. string xmlLang = null;
  132. int i;
  133. for (i = 0; i < openElements.Count; i++)
  134. {
  135. xmlLang = ((XmlTextWriterOpenElement)openElements.ToArray().GetValue(i)).XmlLang;
  136. if (xmlLang != null)
  137. break;
  138. }
  139. return xmlLang;
  140. }
  141. }
  142. public override XmlSpace XmlSpace {
  143. get {
  144. XmlSpace xmlSpace = XmlSpace.None;
  145. int i;
  146. for (i = 0; i < openElements.Count; i++)
  147. {
  148. xmlSpace = ((XmlTextWriterOpenElement)openElements.ToArray().GetValue(i)).XmlSpace;
  149. if (xmlSpace != XmlSpace.None)
  150. break;
  151. }
  152. return xmlSpace;
  153. }
  154. }
  155. #endregion
  156. #region Methods
  157. private void AddMissingElementXmlns ()
  158. {
  159. // output namespace declaration if not exist.
  160. string prefix = openElementPrefix;
  161. string ns = openElementNS;
  162. openElementPrefix = null;
  163. openElementNS = null;
  164. // LAMESPEC: If prefix was already assigned another nsuri, then this element's nsuri goes away!
  165. if (ns != null)
  166. {
  167. string formatXmlns = String.Empty;
  168. if (ns != String.Empty)
  169. {
  170. if (prefix == String.Empty)
  171. prefix = namespaceManager.LookupPrefix (ns);
  172. if (openElementNsAdded)
  173. {
  174. if (prefix != string.Empty)
  175. formatXmlns = String.Format (" xmlns:{0}={1}{2}{1}", prefix, quoteChar, ns);
  176. else
  177. formatXmlns = String.Format (" xmlns={0}{1}{0}", quoteChar, ns);
  178. }
  179. }
  180. else if ((prefix == String.Empty) && (namespaceManager.LookupNamespace (prefix) != ns))
  181. {
  182. namespaceManager.AddNamespace (prefix, ns);
  183. formatXmlns = String.Format (" xmlns={0}{0}", quoteChar);
  184. }
  185. if(formatXmlns != String.Empty) {
  186. string xmlns = formatXmlns.Trim ();
  187. if (checkMultipleAttributes && !writtenAttributes.Contains (xmlns.Substring (0, xmlns.IndexOf ('='))))
  188. w.Write(formatXmlns);
  189. }
  190. }
  191. for (int n=0; n<newAttributeNamespaces.Count; n++)
  192. {
  193. string ans = (string)newAttributeNamespaces[n];
  194. string aprefix = namespaceManager.LookupPrefix (ans);
  195. string formatXmlns = String.Format (" xmlns:{0}={1}{2}{1}", aprefix, quoteChar, ans);
  196. w.Write(formatXmlns);
  197. }
  198. newAttributeNamespaces.Clear ();
  199. }
  200. private void CheckState ()
  201. {
  202. if (!openWriter) {
  203. throw new InvalidOperationException ("The Writer is closed.");
  204. }
  205. if ((documentStarted == true) && (formatting == Formatting.Indented) && (!IndentingOverriden)) {
  206. indentFormatting = w.NewLine;
  207. if (indentLevel > 0) {
  208. for (int i = 0; i < indentLevel; i++)
  209. indentFormatting += indentChars;
  210. }
  211. }
  212. else
  213. indentFormatting = "";
  214. documentStarted = true;
  215. }
  216. public override void Close ()
  217. {
  218. CloseOpenAttributeAndElements ();
  219. w.Close();
  220. ws = WriteState.Closed;
  221. openWriter = false;
  222. }
  223. private void CloseOpenAttributeAndElements ()
  224. {
  225. if (openAttribute)
  226. WriteEndAttribute ();
  227. while (openElements.Count > 0) {
  228. WriteEndElement();
  229. }
  230. }
  231. private void CloseStartElement ()
  232. {
  233. if (!openStartElement)
  234. return;
  235. AddMissingElementXmlns ();
  236. w.Write (">");
  237. ws = WriteState.Content;
  238. openStartElement = false;
  239. attributeWrittenForElement = false;
  240. checkMultipleAttributes = false;
  241. writtenAttributes.Clear ();
  242. newAttributeNamespaces.Clear ();
  243. }
  244. public override void Flush ()
  245. {
  246. // CloseOpenAttributeAndElements ();
  247. w.Flush ();
  248. }
  249. public override string LookupPrefix (string ns)
  250. {
  251. string prefix = namespaceManager.LookupPrefix (ns);
  252. // XmlNamespaceManager has changed to return null when NSURI not found.
  253. // (Contradiction to the documentation.)
  254. //if (prefix == String.Empty)
  255. // prefix = null;
  256. return prefix;
  257. }
  258. private void UpdateIndentChars ()
  259. {
  260. indentChars = "";
  261. for (int i = 0; i < indentation; i++)
  262. indentChars += indentChar;
  263. }
  264. public override void WriteBase64 (byte[] buffer, int index, int count)
  265. {
  266. w.Write (Convert.ToBase64String (buffer, index, count));
  267. }
  268. [MonoTODO]
  269. public override void WriteBinHex (byte[] buffer, int index, int count)
  270. {
  271. throw new NotImplementedException ();
  272. }
  273. public override void WriteCData (string text)
  274. {
  275. if (text.IndexOf("]]>") > 0)
  276. throw new ArgumentException ();
  277. CheckState ();
  278. CloseStartElement ();
  279. w.Write("<![CDATA[{0}]]>", text);
  280. }
  281. public override void WriteCharEntity (char ch)
  282. {
  283. Int16 intCh = (Int16)ch;
  284. // Make sure the character is not in the surrogate pair
  285. // character range, 0xd800- 0xdfff
  286. if ((intCh >= -10240) && (intCh <= -8193))
  287. throw new ArgumentException ("Surrogate Pair is invalid.");
  288. w.Write("&#x{0:X};", intCh);
  289. }
  290. [MonoTODO]
  291. public override void WriteChars (char[] buffer, int index, int count)
  292. {
  293. throw new NotImplementedException ();
  294. }
  295. public override void WriteComment (string text)
  296. {
  297. if ((text.EndsWith("-")) || (text.IndexOf("-->") > 0)) {
  298. throw new ArgumentException ();
  299. }
  300. CheckState ();
  301. CloseStartElement ();
  302. w.Write ("<!--{0}-->", text);
  303. }
  304. public override void WriteDocType (string name, string pubid, string sysid, string subset)
  305. {
  306. if (name == null || name.Trim ().Length == 0)
  307. throw new ArgumentException ("Invalid DOCTYPE name", "name");
  308. w.Write ("<!DOCTYPE ");
  309. w.Write (name);
  310. if (pubid != null) {
  311. w.Write (String.Format (" PUBLIC {0}{1}{0} {0}{2}{0}", quoteChar, pubid, sysid));
  312. } else if (sysid != null) {
  313. w.Write (String.Format (" SYSTEM {0}{1}{0}", quoteChar, sysid));
  314. }
  315. if (subset != null)
  316. w.Write ("[" + subset + "]");
  317. w.Write('>');
  318. }
  319. public override void WriteEndAttribute ()
  320. {
  321. if (!openAttribute)
  322. throw new InvalidOperationException("Token EndAttribute in state Start would result in an invalid XML document.");
  323. CheckState ();
  324. if (openXmlLang) {
  325. w.Write (xmlLang);
  326. openXmlLang = false;
  327. ((XmlTextWriterOpenElement)openElements.Peek()).XmlLang = xmlLang;
  328. }
  329. if (openXmlSpace)
  330. {
  331. w.Write (xmlSpace.ToString ().ToLower ());
  332. openXmlSpace = false;
  333. ((XmlTextWriterOpenElement)openElements.Peek()).XmlSpace = xmlSpace;
  334. }
  335. w.Write ("{0}", quoteChar);
  336. openAttribute = false;
  337. }
  338. public override void WriteEndDocument ()
  339. {
  340. CloseOpenAttributeAndElements ();
  341. if (!hasRoot)
  342. throw new ArgumentException ("This document does not have a root element.");
  343. ws = WriteState.Start;
  344. hasRoot = false;
  345. }
  346. public override void WriteEndElement ()
  347. {
  348. WriteEndElementInternal (false);
  349. }
  350. private void WriteEndElementInternal (bool fullEndElement)
  351. {
  352. if (openElements.Count == 0)
  353. throw new InvalidOperationException("There was no XML start tag open.");
  354. indentLevel--;
  355. CheckState ();
  356. AddMissingElementXmlns ();
  357. if (openStartElement) {
  358. if (openAttribute)
  359. WriteEndAttribute ();
  360. if (fullEndElement)
  361. w.Write ("></{0}>", ((XmlTextWriterOpenElement)openElements.Peek ()).Name);
  362. else
  363. w.Write (" />");
  364. openElements.Pop ();
  365. openStartElement = false;
  366. } else {
  367. w.Write ("{0}</{1}>", indentFormatting, openElements.Pop ());
  368. }
  369. namespaceManager.PopScope();
  370. }
  371. public override void WriteEntityRef (string name)
  372. {
  373. WriteRaw ("&");
  374. WriteStringInternal (name, true);
  375. WriteRaw (";");
  376. }
  377. public override void WriteFullEndElement ()
  378. {
  379. WriteEndElementInternal (true);
  380. }
  381. private void CheckValidChars (string name, bool firstOnlyLetter)
  382. {
  383. foreach (char c in name) {
  384. if (XmlConvert.IsInvalid (c, firstOnlyLetter))
  385. throw new ArgumentException ("There is an invalid character: '" + c +
  386. "'", "name");
  387. }
  388. }
  389. public override void WriteName (string name)
  390. {
  391. CheckValidChars (name, true);
  392. w.Write (name);
  393. }
  394. public override void WriteNmToken (string name)
  395. {
  396. CheckValidChars (name, false);
  397. w.Write (name);
  398. }
  399. public override void WriteProcessingInstruction (string name, string text)
  400. {
  401. if ((name == null) || (name == string.Empty) || (name.IndexOf("?>") > 0) || (text.IndexOf("?>") > 0)) {
  402. throw new ArgumentException ();
  403. }
  404. CheckState ();
  405. CloseStartElement ();
  406. w.Write ("{0}<?{1} {2}?>", indentFormatting, name, text);
  407. }
  408. [MonoTODO]
  409. public override void WriteQualifiedName (string localName, string ns)
  410. {
  411. if (localName == null || localName == String.Empty)
  412. throw new ArgumentException ();
  413. CheckState ();
  414. if (!openAttribute)
  415. CloseStartElement ();
  416. string prefix = namespaceManager.LookupPrefix (ns);
  417. w.Write ("{0}:{1}", prefix, localName);
  418. }
  419. public override void WriteRaw (string data)
  420. {
  421. WriteStringInternal (data, false);
  422. }
  423. public override void WriteRaw (char[] buffer, int index, int count)
  424. {
  425. // WriteRawInternal (new string (buffer, index, count));
  426. WriteStringInternal (new string (buffer, index, count), false);
  427. }
  428. public override void WriteStartAttribute (string prefix, string localName, string ns)
  429. {
  430. if ((prefix == "xml") && (localName == "lang"))
  431. openXmlLang = true;
  432. if ((prefix == "xml") && (localName == "space"))
  433. openXmlSpace = true;
  434. if ((prefix == "xmlns") && (localName.ToLower ().StartsWith ("xml")))
  435. throw new ArgumentException ("Prefixes beginning with \"xml\" (regardless of whether the characters are uppercase, lowercase, or some combination thereof) are reserved for use by XML: " + prefix + ":" + localName);
  436. if ((prefix == "xmlns") && (ns != "http://www.w3.org/2000/xmlns/"))
  437. throw new ArgumentException ("The 'xmlns' attribute is bound to the reserved namespace 'http://www.w3.org/2000/xmlns/'");
  438. CheckState ();
  439. if (ws == WriteState.Content)
  440. throw new InvalidOperationException ("Token StartAttribute in state " + WriteState + " would result in an invalid XML document.");
  441. if (prefix == null)
  442. prefix = String.Empty;
  443. if (ns == null)
  444. ns = String.Empty;
  445. string formatPrefix = "";
  446. string formatSpace = "";
  447. if (ns != String.Empty && prefix != "xmlns")
  448. {
  449. string existingPrefix = namespaceManager.LookupPrefix (ns);
  450. if (existingPrefix == null)
  451. {
  452. newAttributeNamespaces.Add (ns);
  453. prefix = "d" + indentLevel + "p" + newAttributeNamespaces.Count;
  454. namespaceManager.AddNamespace (prefix, ns);
  455. }
  456. if (prefix == String.Empty && ns != "http://www.w3.org/2000/xmlns/")
  457. prefix = (existingPrefix == null) ?
  458. String.Empty : existingPrefix;
  459. }
  460. if (prefix != String.Empty)
  461. {
  462. formatPrefix = prefix + ":";
  463. }
  464. if (openStartElement || attributeWrittenForElement)
  465. formatSpace = " ";
  466. // If already written, then break up.
  467. if (checkMultipleAttributes &&
  468. writtenAttributes.Contains (formatPrefix + localName))
  469. return;
  470. w.Write ("{0}{1}{2}={3}", formatSpace, formatPrefix, localName, quoteChar);
  471. if (checkMultipleAttributes)
  472. writtenAttributes.Add (formatPrefix + localName, formatPrefix + localName);
  473. openAttribute = true;
  474. attributeWrittenForElement = true;
  475. ws = WriteState.Attribute;
  476. /* This is managed in WriteAttributeString.
  477. if (prefix == String.Empty && localName == "xmlns") {
  478. if (namespaceManager.LookupNamespace (prefix) == null)
  479. namespaceManager.AddNamespace (prefix, ns);
  480. } else if (prefix == "xmlns") {
  481. if (namespaceManager.LookupNamespace (localName) == null)
  482. namespaceManager.AddNamespace (localName, ns);
  483. }
  484. */
  485. }
  486. public override void WriteStartDocument ()
  487. {
  488. WriteStartDocument ("");
  489. }
  490. public override void WriteStartDocument (bool standalone)
  491. {
  492. string standaloneFormatting;
  493. if (standalone == true)
  494. standaloneFormatting = String.Format (" standalone={0}yes{0}", quoteChar);
  495. else
  496. standaloneFormatting = String.Format (" standalone={0}no{0}", quoteChar);
  497. WriteStartDocument (standaloneFormatting);
  498. }
  499. private void WriteStartDocument (string standaloneFormatting)
  500. {
  501. if (documentStarted == true)
  502. throw new InvalidOperationException("WriteStartDocument should be the first call.");
  503. if (hasRoot)
  504. throw new XmlException ("WriteStartDocument called twice.");
  505. CheckState ();
  506. string encodingFormatting = "";
  507. if (!nullEncoding)
  508. encodingFormatting = String.Format (" encoding={0}{1}{0}", quoteChar, w.Encoding.WebName);
  509. w.Write("<?xml version={0}1.0{0}{1}{2}?>", quoteChar, encodingFormatting, standaloneFormatting);
  510. ws = WriteState.Prolog;
  511. }
  512. public override void WriteStartElement (string prefix, string localName, string ns)
  513. {
  514. if (!Namespaces && (((prefix != null) && (prefix != String.Empty))
  515. || ((ns != null) && (ns != String.Empty))))
  516. throw new ArgumentException ("Cannot set the namespace if Namespaces is 'false'.");
  517. WriteStartElementInternal (prefix, localName, ns);
  518. }
  519. private void WriteStartElementInternal (string prefix, string localName, string ns)
  520. {
  521. if ((prefix != null && prefix != String.Empty) && ((ns == null) || (ns == String.Empty)))
  522. throw new ArgumentException ("Cannot use a prefix with an empty namespace.");
  523. hasRoot = true;
  524. CheckState ();
  525. CloseStartElement ();
  526. writtenAttributes.Clear ();
  527. newAttributeNamespaces.Clear ();
  528. checkMultipleAttributes = true;
  529. if (prefix == null)
  530. prefix = namespaceManager.LookupPrefix (ns);
  531. if (prefix == null)
  532. prefix = String.Empty;
  533. string formatPrefix = "";
  534. if(ns != null) {
  535. if (prefix != String.Empty)
  536. formatPrefix = prefix + ":";
  537. }
  538. w.Write ("{0}<{1}{2}", indentFormatting, formatPrefix, localName);
  539. openElements.Push (new XmlTextWriterOpenElement (formatPrefix + localName));
  540. ws = WriteState.Element;
  541. openStartElement = true;
  542. openElementNS = ns;
  543. openElementPrefix = prefix;
  544. openElementNsAdded = false;
  545. namespaceManager.PushScope ();
  546. indentLevel++;
  547. if (ns != null && ns != string.Empty && namespaceManager.LookupPrefix (ns) == null)
  548. {
  549. namespaceManager.AddNamespace (prefix, ns);
  550. openElementNsAdded = true;
  551. }
  552. }
  553. public override void WriteString (string text)
  554. {
  555. if (ws == WriteState.Prolog)
  556. throw new InvalidOperationException ("Token content in state Prolog would result in an invalid XML document.");
  557. WriteStringInternal (text, true);
  558. }
  559. private string NormalizeAttributeString (string value)
  560. {
  561. return value.Replace ("\r", "&#xD;").Replace ("\n", "&#xA;");
  562. }
  563. private void WriteStringInternal (string text, bool entitize)
  564. {
  565. if (text == null)
  566. text = String.Empty;
  567. if (text != String.Empty) {
  568. CheckState ();
  569. if (entitize)
  570. {
  571. text = text.Replace ("&", "&amp;");
  572. text = text.Replace ("<", "&lt;");
  573. text = text.Replace (">", "&gt;");
  574. if (openAttribute)
  575. {
  576. if (quoteChar == '"')
  577. text = text.Replace ("\"", "&quot;");
  578. else
  579. text = text.Replace ("'", "&apos;");
  580. text = NormalizeAttributeString (text);
  581. }
  582. }
  583. if (!openAttribute)
  584. {
  585. IndentingOverriden = true;
  586. CloseStartElement ();
  587. }
  588. if (!openXmlLang && !openXmlSpace)
  589. w.Write (text);
  590. else
  591. {
  592. if (openXmlLang)
  593. xmlLang = text;
  594. else
  595. {
  596. switch (text)
  597. {
  598. case "default":
  599. xmlSpace = XmlSpace.Default;
  600. break;
  601. case "preserve":
  602. xmlSpace = XmlSpace.Preserve;
  603. break;
  604. default:
  605. throw new ArgumentException ("'{0}' is an invalid xml:space value.");
  606. }
  607. }
  608. }
  609. }
  610. }
  611. [MonoTODO]
  612. public override void WriteSurrogateCharEntity (char lowChar, char highChar)
  613. {
  614. throw new NotImplementedException ();
  615. }
  616. public override void WriteWhitespace (string ws)
  617. {
  618. foreach (char c in ws) {
  619. if ((c != ' ') && (c != '\t') && (c != '\r') && (c != '\n'))
  620. throw new ArgumentException ();
  621. }
  622. CheckState ();
  623. if (!openAttribute) {
  624. IndentingOverriden = true;
  625. CloseStartElement ();
  626. }
  627. w.Write (ws);
  628. }
  629. #endregion
  630. }
  631. }