public override void Save(string filename) { XmlWriter xmlWriter = null; try { if (PreserveWhitespace) { XmlFormatter.Format(this); xmlWriter = new XmlAttributePreservingWriter(filename, TextEncoding); } else { var textWriter = new XmlTextWriter(filename, TextEncoding) { Formatting = Formatting.Indented }; xmlWriter = textWriter; } WriteTo(xmlWriter); } finally { if (xmlWriter != null) { xmlWriter.Flush(); xmlWriter.Close(); } } }
public override void Save(Stream w) { XmlWriter xmlWriter = null; try { if (PreserveWhitespace) { XmlFormatter.Format(this); xmlWriter = new XmlAttributePreservingWriter(w, TextEncoding); } else { XmlTextWriter textWriter = new XmlTextWriter(w, TextEncoding) { Formatting = Formatting.Indented }; xmlWriter = textWriter; } WriteTo(xmlWriter); } finally { xmlWriter?.Flush(); } }
public override void Save(Stream w) { XmlWriter xmlWriter = null; try { if (PreserveWhitespace) { XmlFormatter.Format(this); xmlWriter = new XmlAttributePreservingWriter(w, TextEncoding); } else { xmlWriter = XmlWriter.Create(w, new XmlWriterSettings { Encoding = TextEncoding, Indent = true, }); } WriteTo(xmlWriter); } finally { xmlWriter?.Flush(); } }
internal void WritePreservedAttributes(XmlAttributePreservingWriter writer, XmlAttributeCollection attributes) { string oldNewLineString = null; if (_attributeNewLineString != null) { oldNewLineString = writer.SetAttributeNewLineString(_attributeNewLineString); } try { foreach (string attributeName in _orderedAttributes) { XmlAttribute attr = attributes[attributeName]; if (attr == null) { continue; } if (_leadingSpaces.ContainsKey(attributeName)) { writer.WriteAttributeWhitespace(_leadingSpaces[attributeName]); } attr.WriteTo(writer); } if (_leadingSpaces.ContainsKey(string.Empty)) { writer.WriteAttributeTrailingWhitespace(_leadingSpaces[string.Empty]); } } finally { if (oldNewLineString != null) { writer.SetAttributeNewLineString(oldNewLineString); } } }
void WritePreservedAttributesTo(XmlAttributePreservingWriter preservingWriter) => _preservationDict.WritePreservedAttributes(preservingWriter, Attributes);