AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="0.9.7" />

 XmlParser

public class XmlParser
Creates an instance of the XML parser front-end.
using AngleSharp.Dom.Xml; using AngleSharp.Extensions; using System.IO; using System.Threading; using System.Threading.Tasks; namespace AngleSharp.Parser.Xml { public class XmlParser { private readonly XmlParserOptions _options; private readonly IBrowsingContext _context; public XmlParserOptions Options => _options; public IBrowsingContext Context => _context; public XmlParser() : this(Configuration.Default) { } public XmlParser(XmlParserOptions options) : this(options, Configuration.Default) { } public XmlParser(IConfiguration configuration) : this(default(XmlParserOptions), configuration) { } public XmlParser(XmlParserOptions options, IConfiguration configuration) : this(options, BrowsingContext.New(configuration)) { } public XmlParser(XmlParserOptions options, IBrowsingContext context) { _options = options; _context = context; } public IXmlDocument Parse(string source) { XmlDocument xmlDocument = CreateDocument(source); new XmlDomBuilder(xmlDocument, null).Parse(_options); return xmlDocument; } public IXmlDocument Parse(Stream source) { XmlDocument xmlDocument = CreateDocument(source); new XmlDomBuilder(xmlDocument, null).Parse(_options); return xmlDocument; } public Task<IXmlDocument> ParseAsync(string source) { return ParseAsync(source, CancellationToken.None); } public Task<IXmlDocument> ParseAsync(Stream source) { return ParseAsync(source, CancellationToken.None); } public async Task<IXmlDocument> ParseAsync(string source, CancellationToken cancel) { XmlDocument document = CreateDocument(source); await new XmlDomBuilder(document, null).ParseAsync(_options, cancel).ConfigureAwait(false); return document; } public async Task<IXmlDocument> ParseAsync(Stream source, CancellationToken cancel) { XmlDocument document = CreateDocument(source); await new XmlDomBuilder(document, null).ParseAsync(_options, cancel).ConfigureAwait(false); return document; } private XmlDocument CreateDocument(string source) { TextSource textSource = new TextSource(source); return CreateDocument(textSource); } private XmlDocument CreateDocument(Stream source) { TextSource textSource = new TextSource(source, _context.Configuration.DefaultEncoding()); return CreateDocument(textSource); } private XmlDocument CreateDocument(TextSource textSource) { return new XmlDocument(_context, textSource); } } }