예제 #1
0
        public static string ToString([NotNull] this XNode xml, bool format, Encoding encoding)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }

            encoding = encoding ?? Encoding.Unicode;

            var settings = new XmlWriterSettings {
                Encoding = encoding
            };

            if (format)
            {
                settings.Indent      = true;
                settings.IndentChars = "\t";
            }

            var stream = new EncodeSpecifiedStringWriter(encoding);

            using (var xw = XmlWriter.Create(stream, settings))
            {
                xml.WriteTo(xw);
                xw.Flush();

                return(stream.ToString());
            }
        }
예제 #2
0
        public static string ToString([NotNull] this XDocument xml, bool format, Encoding encoding)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }

            using (var stream = new EncodeSpecifiedStringWriter(encoding ?? Encoding.Unicode))
            {
                xml.Save(stream, format ? SaveOptions.None : SaveOptions.DisableFormatting);

                return(stream.ToString());
            }
        }
예제 #3
0
		public static string ToString ([NotNull] this XDocument xml, bool format, Encoding encoding)
		{
			if (xml == null)
				throw new ArgumentNullException ("xml");

			using (var stream = new EncodeSpecifiedStringWriter (encoding ?? Encoding.Unicode))
			{
				xml.Save (stream, format ? SaveOptions.None : SaveOptions.DisableFormatting);

				return stream.ToString ();
			}
		}
예제 #4
0
		public static string ToString ([NotNull] this XNode xml, bool format, Encoding encoding)
		{
			if (xml == null)
				throw new ArgumentNullException ("xml");

			encoding = encoding ?? Encoding.Unicode;

			var settings = new XmlWriterSettings { Encoding = encoding };

			if (format)
			{
				settings.Indent = true;
				settings.IndentChars = "\t";
			}

			var stream = new EncodeSpecifiedStringWriter (encoding);

			using (var xw = XmlWriter.Create (stream, settings))
			{
				xml.WriteTo (xw);
				xw.Flush ();

				return stream.ToString ();
			}
		}