public XmlFormatterWriter (TextWriter writer) { if (writer == null) throw new ArgumentNullException ("writer"); ignore_encoding = (writer.Encoding == null); Initialize (writer); allow_doc_fragment = true; xmldecl_state = formatSettings.OmitXmlDeclaration ? XmlDeclState.Ignore : XmlDeclState.Allow; newline = formatSettings.NewLineChars; check_character_validity = false; v2 = true; }
void WriteStartDocumentCore (bool outputStd, bool standalone) { if (state != WriteState.Start) throw StateError ("XmlDeclaration"); switch (xmldecl_state) { case XmlDeclState.Ignore: return; case XmlDeclState.Prohibit: throw InvalidOperation ("WriteStartDocument cannot be called when ConformanceLevel is Fragment."); } state = WriteState.Prolog; writer.Write ("<?xml version="); writer.Write (formatSettings.QuoteChar); writer.Write ("1.0"); writer.Write (formatSettings.QuoteChar); if (!ignore_encoding) { writer.Write (" encoding="); writer.Write (formatSettings.QuoteChar); writer.Write (writer.Encoding.WebName); writer.Write (formatSettings.QuoteChar); } if (outputStd) { writer.Write (" standalone="); writer.Write (formatSettings.QuoteChar); writer.Write (standalone ? "yes" : "no"); writer.Write (formatSettings.QuoteChar); } writer.Write ("?>"); xmldecl_state = XmlDeclState.Ignore; }
internal XmlTextWriter ( TextWriter writer, XmlWriterSettings settings, bool closeOutput) { v2 = true; if (settings == null) settings = new XmlWriterSettings (); newline_handling = settings.NewLineHandling; Initialize (writer); close_output_stream = closeOutput; allow_doc_fragment = settings.ConformanceLevel != ConformanceLevel.Document; switch (settings.ConformanceLevel) { case ConformanceLevel.Auto: xmldecl_state = settings.OmitXmlDeclaration ? XmlDeclState.Ignore : XmlDeclState.Allow; break; case ConformanceLevel.Document: // LAMESPEC: // On MSDN, XmlWriterSettings.OmitXmlDeclaration is documented as: // "The XML declaration is always written if // ConformanceLevel is set to Document, even // if OmitXmlDeclaration is set to true. " // but it is incorrect. It does consider // OmitXmlDeclaration property. xmldecl_state = settings.OmitXmlDeclaration ? XmlDeclState.Ignore : XmlDeclState.Auto; break; case ConformanceLevel.Fragment: xmldecl_state = XmlDeclState.Prohibit; break; } if (settings.Indent) Formatting = Formatting.Indented; indent_string = settings.IndentChars == null ? String.Empty : settings.IndentChars; if (settings.NewLineChars != null) newline = settings.NewLineChars; indent_attributes = settings.NewLineOnAttributes; check_character_validity = settings.CheckCharacters; namespace_handling = settings.NamespaceHandling; }