/// <summary> /// Switches to the fragment algorithm with the specified context /// element. Then parses the given source and creates the document. /// </summary> /// <param name="options">The options to use for parsing.</param> /// <param name="context"> /// The context element where the algorithm is applied to. /// </param> public Document ParseFragment(XmlParserOptions options, Element context) { context = context ?? throw new ArgumentNullException(nameof(context)); var root = new XmlElement(_document, context.LocalName); _document.AddNode(root); _openElements.Add(root); return(Parse(options)); }
/// <summary> /// Parses the given source and creates the document. /// </summary> /// <param name="options">The options to use for parsing.</param> public Document Parse(XmlParserOptions options) { var token = default(XmlToken); _options = options; _tokenizer.IsSuppressingErrors = options.IsSuppressingErrors; do { token = _tokenizer.Get(); Consume(token); }while (token.Type != XmlTokenType.EndOfFile); return(_document); }
/// <summary> /// Parses the given source asynchronously and creates the document. /// </summary> /// <param name="options">The options to use for parsing.</param> /// <param name="cancelToken">The cancellation token to use.</param> public async Task <Document> ParseAsync(XmlParserOptions options, CancellationToken cancelToken) { var source = _document.Source; var token = default(XmlToken); _options = options; _tokenizer.IsSuppressingErrors = options.IsSuppressingErrors; do { if (source.Length - source.Index < 1024) { await source.PrefetchAsync(8192, cancelToken).ConfigureAwait(false); } token = _tokenizer.Get(); Consume(token); }while (token.Type != XmlTokenType.EndOfFile); return(_document); }
/// <summary> /// Creates a new parser with the custom options and the given context. /// </summary> /// <param name="options">The options to use.</param> /// <param name="context">The context to use.</param> public XmlParser(XmlParserOptions options, IBrowsingContext context) { _options = options; _context = context ?? BrowsingContext.NewFrom <IXmlParser>(this); }
/// <summary> /// Creates a new parser with the custom options. /// </summary> /// <param name="options">The options to use.</param> public XmlParser(XmlParserOptions options) : this(options, default(IBrowsingContext)) { }