Beispiel #1
0
        /// <summary>
        /// Returns an <see cref="XmlReader"/> over a <see cref="StringBuilder"/> that contains XML data. Provided that
        /// the content is not empty, the <see cref="XmlReader"/> will be positioned at the first content node.
        /// </summary>
        /// <param name="builder">
        /// The <see cref="StringBuilder"/> containing the XML data.
        /// </param>
        /// <returns>
        /// An <see cref="XmlReader"/> over the XML content of the <see cref="StringBuilder"/>.
        /// </returns>
        public static XmlReader GetReaderAtContent(this StringBuilder builder)
        {
            var xmlReader = builder.ToString().Trim()
                            .IfNotNullOrEmpty(s => XmlReader.Create(new StringReader(s), new XmlReaderSettings {
                CloseInput = true
            }))
                            ?? EmptyXmlReader.Create();

            xmlReader.MoveToContent();
            return(xmlReader);
        }
        public static XmlReader GetReaderAtContent(this StringBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            var xmlReader = builder.ToString().Trim()
                            .IfNotNullOrEmpty(s => XmlReader.Create(new StringReader(s), new() { CloseInput = true, XmlResolver = null }))
                            ?? EmptyXmlReader.Create();

            xmlReader.MoveToContent();
            return(xmlReader);
        }