// // Private methods // void Initialize() { encoding = Encoding.UTF8; omitXmlDecl = false; newLineHandling = NewLineHandling.Replace; newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix indent = TriState.Unknown; indentChars = " "; newLineOnAttributes = false; closeOutput = false; namespaceHandling = NamespaceHandling.Default; conformanceLevel = ConformanceLevel.Document; checkCharacters = true; writeEndDocumentOnClose = true; #if !SILVERLIGHT outputMethod = XmlOutputMethod.Xml; cdataSections.Clear(); mergeCDataSections = false; mediaType = null; docTypeSystem = null; docTypePublic = null; standalone = XmlStandalone.Omit; doNotEscapeUriAttributes = false; #endif #if ASYNC || FEATURE_NETCORE useAsync = false; #endif isReadOnly = false; }
// // Private methods // private void Initialize() { _encoding = Encoding.UTF8; _omitXmlDecl = false; _newLineHandling = NewLineHandling.Replace; _newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix _indent = TriState.Unknown; _indentChars = " "; _newLineOnAttributes = false; _closeOutput = false; _namespaceHandling = NamespaceHandling.Default; _conformanceLevel = ConformanceLevel.Document; _checkCharacters = true; _writeEndDocumentOnClose = true; _outputMethod = XmlOutputMethod.Xml; _cdataSections.Clear(); _mergeCDataSections = false; _mediaType = null; _docTypeSystem = null; _docTypePublic = null; _standalone = XmlStandalone.Omit; _doNotEscapeUriAttributes = false; _useAsync = false; _isReadOnly = false; }
private string SaveXElementUsingXmlWriter(XElement elem, NamespaceHandling nsHandling) { StringWriter sw = new StringWriter(); using (XmlWriter w = XmlWriter.Create(sw, new XmlWriterSettings() { NamespaceHandling = nsHandling, OmitXmlDeclaration = true })) { elem.WriteTo(w); } sw.Dispose(); return sw.ToString(); }
private string SaveXElementUsingXmlWriter(XElement elem, NamespaceHandling nsHandling) { StringWriter sw = new StringWriter(); using (XmlWriter w = XmlWriter.Create(sw, new XmlWriterSettings() { NamespaceHandling = nsHandling, OmitXmlDeclaration = true })) { elem.WriteTo(w); } sw.Dispose(); return(sw.ToString()); }
// // Private methods // private void Initialize() { _encoding = Encoding.UTF8; _omitXmlDecl = false; _newLineHandling = NewLineHandling.Replace; _newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix _indent = TriState.Unknown; _indentChars = " "; _newLineOnAttributes = false; _closeOutput = false; _namespaceHandling = NamespaceHandling.Default; _conformanceLevel = ConformanceLevel.Document; _checkCharacters = true; _writeEndDocumentOnClose = true; _useAsync = false; _isReadOnly = false; }
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; }