AngleSharp by AngleSharp

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

.NET API 888,320 bytes

 DomImplementation

Provides a number of methods for performing operations that are independent of any particular instance of the DOM.
using AngleSharp.Html.Dom; using AngleSharp.Text; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace AngleSharp.Dom { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal sealed class DomImplementation : IImplementation { private static readonly Dictionary<string, string[]> features = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase) { { "XML", new string[2] { "1.0", "2.0" } }, { "HTML", new string[2] { "1.0", "2.0" } }, { "Core", new string[1] { "2.0" } }, { "Views", new string[1] { "2.0" } }, { "StyleSheets", new string[1] { "2.0" } }, { "CSS", new string[1] { "2.0" } }, { "CSS2", new string[1] { "2.0" } }, { "Traversal", new string[1] { "2.0" } }, { "Events", new string[1] { "2.0" } }, { "UIEvents", new string[1] { "2.0" } }, { "HTMLEvents", new string[1] { "2.0" } }, { "Range", new string[1] { "2.0" } }, { "MutationEvents", new string[1] { "2.0" } } }; private readonly Document _owner; public DomImplementation(Document owner) { _owner = owner; } public IDocumentType CreateDocumentType(string qualifiedName, string publicId, string systemId) { if (qualifiedName == null) throw new ArgumentNullException("qualifiedName"); if (!qualifiedName.IsXmlName()) throw new DomException(DomError.InvalidCharacter); if (!qualifiedName.IsQualifiedName()) throw new DomException(DomError.Namespace); return new DocumentType(_owner, qualifiedName) { PublicIdentifier = publicId, SystemIdentifier = systemId }; } public IDocument CreateHtmlDocument(string title) { HtmlDocument htmlDocument = new HtmlDocument(null); htmlDocument.AppendChild(new DocumentType(htmlDocument, TagNames.Html)); htmlDocument.AppendChild(htmlDocument.CreateElement(TagNames.Html)); htmlDocument.DocumentElement.AppendChild(htmlDocument.CreateElement(TagNames.Head)); if (!string.IsNullOrEmpty(title)) { IElement element = htmlDocument.CreateElement(TagNames.Title); element.AppendChild(htmlDocument.CreateTextNode(title)); htmlDocument.Head.AppendChild(element); } htmlDocument.DocumentElement.AppendChild(htmlDocument.CreateElement(TagNames.Body)); htmlDocument.BaseUrl = _owner.BaseUrl; return htmlDocument; } public bool HasFeature(string feature, [System.Runtime.CompilerServices.Nullable(2)] string version = null) { if (feature == null) throw new ArgumentNullException("feature"); if (features.TryGetValue(feature, out string[] value)) return value.Contains(version ?? string.Empty, StringComparison.OrdinalIgnoreCase); return false; } } }