AngleSharp.Xml is the AngleSharp ecosystem's XML extension library. It provides:
- XML parsing and serialization
- XML and SVG document integration with AngleSharp BrowsingContext
- An AngleSharp DOM model for XML documents
- XML fragments and asynchronous parsing
- DTD parsing and practical validity checks
- Namespace-aware XML handling
The package is published as AngleSharp.Xml and is MIT licensed. The repository is hosted at https://github.com/AngleSharp/AngleSharp.Xml.
The public README describes the intended positioning: XML behavior that integrates with AngleSharp's DOM, configuration, loading, SVG, XHTML, and formatting APIs. Do not assume this project should be made equivalent to System.Xml; preserve the AngleSharp integration model.
- Primary development branch is
devel. - The repository currently uses the Fallout build orchestrator, version 10.4.x in the checked-in build tooling.
- The current project version in
src/Directory.Build.propsis1.2.0. - The package's AngleSharp dependency defaults to version
1.5.0and allows versions below2.0.0. - There is no repository-level AGENTS.md or copilot instruction file other than this one.
- The worktree should be checked with
git status --shortbefore making assumptions about local changes. Never discard changes that are already present.
From the repository root:
dotnet test src/AngleSharp.Xml.Tests/AngleSharp.Xml.Tests.csproj -v qThe tests target net8.0. The test project references the library with its netstandard2.0 target framework, so a test-only run does not necessarily exercise every library target framework.
Run one fixture or test with NUnit adapter filtering:
dotnet test src/AngleSharp.Xml.Tests/AngleSharp.Xml.Tests.csproj \
--filter 'FullyQualifiedName~AngleSharp.Xml.Tests.Parser.XmlInvalidDocuments'Use a more specific filter for a single method when debugging. Avoid broad test output when possible; filter or redirect it and inspect the final Test summary.
The supported repository build entry points are:
./build.sh.\build.ps1The scripts:
- Prefer a globally installed
dotnet. - Otherwise install a local SDK under
.fallout/temp. - Restore local .NET tools.
- Invoke the Fallout build target.
The default local target runs restore, compile, tests, and package creation. The build reads the version from CHANGELOG.md and supports parameters such as:
./build.sh -AngleSharpVersion 1.5.0
./build.sh -Target RunUnitTests
./build.sh -Target Compile
./build.sh -Target PackageThe exact target names are defined in build/Build.cs. Important targets include:
CleanRestoreCompileRunUnitTestsCreatePackagePackagePublishPrePublish
Publishing requires secrets and must not be attempted casually:
NUGET_API_KEYfor NuGet publishingGITHUB_TOKENfor GitHub release publishing
Useful focused commands from the root:
dotnet build src/AngleSharp.Xml/AngleSharp.Xml.csproj
dotnet build src/AngleSharp.Xml.Tests/AngleSharp.Xml.Tests.csproj
dotnet test src/AngleSharp.Xml.Tests/AngleSharp.Xml.Tests.csprojThe solution is src/AngleSharp.Xml.sln; it contains the library, tests, and build project. CI uses the repository build scripts rather than direct solution commands.
.github/workflows/ci.yml runs on push and pull request.
- Linux uses .NET
10.0.xand runs./build.sh -AngleSharpVersion 1.5.0. - Windows uses .NET
10.0.xand runsbuild.ps1. - Windows publishes on
main, pre-publishes ondevel, and performs the default build for other refs. - Documentation deployment is conditional on repository secrets and the configured docs branch/path.
src/AngleSharp.Xml/AngleSharp.Xml.csproj targets:
netstandard2.0net8.0net10.0net462andnet472on Windows only
The project enables XML documentation generation, strong-name signing, SourceLink, symbols, and package metadata. Warnings are treated as errors through src/Directory.Build.props.
README.md: package overview and basic XML setup.CHANGELOG.md: release notes and source of the build version.CONTRIBUTORS.md: contributor information.LICENSE: MIT license.build.sh,build.ps1,build.cmd: cross-platform build entry points.build/: Fallout build project and build targets.docs/: Markdown documentation.src/: solution, library, tests, and docs web project.
Public integration and formatter files:
XmlConfigurationExtensions.cs:IConfiguration.WithXml()registration for XML, application/xml, and SVG document factories plusIXmlParser.DomImplementationExtension.cs: XML DOM factory helpers.XmlMarkupFormatter.cs: XML serialization formatter.AutoSelectedMarkupFormatter.csandMarkupFormatterExtensions.cs: formatter selection/helpers.XmlEntityProvider.cs: built-in XML entities (amp;,lt;,gt;,apos;,quot;).
DOM files:
Dom/IXmlDocument.cs: publicIXmlDocument, includingIsValid.Dom/ISvgDocument.cs: SVG document contract.Dom/Internal/XmlDocument.cs: internal XML document implementation and validity storage.Dom/Internal/XmlElement.cs: XML element implementation.Dom/Internal/SvgDocument.cs: SVG document implementation.Dom/Events/XmlParseEvent.cs: parser lifecycle event payload.
Parser files:
Parser/IXmlParser.cs: public parser contract for strings, streams, fragments, and async operations.Parser/XmlParser.cs: parser facade and document creation.Parser/XmlDomBuilder.cs: tree construction, DOCTYPE handling, DTD validation, and entity expansion.Parser/XmlTokenizer.cs: XML lexical tokenizer and character/entity reference handling.Parser/XmlParserOptions.cs: suppress-errors, source-reference, and element-created callback options.Parser/XmlParseError*.cs: parse error definitions and exception mapping.Parser/Tokens/: token models for declarations, DOCTYPE, tags, text, CDATA, comments, processing instructions, and EOF.
DTD files:
Dtd/Parser/DtdParser.cs: DTD parser.Dtd/Parser/DtdTokenizer.cs: DTD lexical/token parsing.Dtd/Parser/DtdPlainTokenizer.cs: plain external DTD tokenization support.Dtd/Parser/DtdContainer.cs: parsed DTD declarations/entities and invalid state.Dtd/Declaration/: element and attribute declaration models.
Parser/XmlParsing.cs: general parser behavior.Parser/XmlNamespace.cs: namespace behavior.Parser/XmlValidDocuments.cs: large valid XML conformance fixture suite.Parser/XmlInvalidDocuments.cs: invalid document/DTD fixture suite.Parser/XmlValidExtDtd.cs: valid external DTD fixtures.Parser/XmlNotWfDocuments.cs: not-well-formed XML fixtures.Parser/XmlNotWfExtDtd.cs: not-well-formed external DTD fixtures.Parser/XmlDtdImplementedCases.cs: focused, currently supported DTD validation cases.Parser/XmlExternalDtdSupport.cs: local-file external DTD/entity regression tests.Tokenizer/XmlDTD.cs: DTD tokenizer/parser samples, including historical commented assertions.Tokenizer/XmlTokenization.cs: XML tokenizer tests.Dom/: DOM samples and tree behavior.Xhtml/: XHTML formatter and preservation tests.Mocks/MockEntityProvider.cs: entity provider test double.TestExtensions.cs: test parsing helpers, including permissive conformance fallback behavior.
The tests use NUnit 3, NUnit3TestAdapter, Microsoft.NET.Test.Sdk, and target net8.0.
Markdown documentation is under docs/:
docs/general/01-Basics.md: setup and NuGet usage.docs/general/02-Capabilities.md: supported capabilities.docs/general/03-Limitations.md: project boundaries.docs/tutorials/01-API.md: parser/configuration APIs.docs/tutorials/02-Examples.md: code examples.docs/tutorials/03-Use-Cases.md: practical workflows.docs/tutorials/04-Questions.md: FAQ.docs/tutorials/05-DTD-Validation.md: DTD concepts, validation, supported behavior, and limitations.
The docs web project is under src/AngleSharp.Xml.Docs and uses Node.js/npm with a TypeScript/React entry point. Its CI deployment is secret-controlled; ordinary library changes generally only need Markdown updates unless the docs web app itself is changed.
var config = Configuration.Default
.WithXml();WithXml() registers document factories for:
text/xmlapplication/xml- SVG content
It also registers an IXmlParser service in the browsing context.
var parser = new XmlParser();
var document = parser.ParseDocument(xmlText);The parser also supports streams, fragments, and asynchronous overloads. XmlParserExtensions supplies cancellation-token-free async convenience methods.
IsSuppressingErrors: recovery mode; the parser attempts to return a document instead of throwing. The resulting DOM may be incomplete or surprising. Do not treat this as strict validation.IsKeepingSourceReferences: keeps source token references on created elements for diagnostics/tooling.OnCreated: callback receiving each created element and itsTextPosition.
IXmlDocument.IsValid is the library's DTD-related validity signal. It is initialized true and is updated after parsing when applicable. A document can be syntactically parsed but invalid according to its DOCTYPE/DTD declarations.
The DTD implementation is useful but intentionally should not be treated as a complete XML 1.0 validation stack.
Currently supported or partially supported behavior includes:
- DOCTYPE root-name consistency checking.
- Internal subset declarations for common validation cases.
- Common element models such as
ANY,EMPTY, mixed(#PCDATA|name|...)*, and simple ordered sequences. - Internal attribute checks, including undeclared attributes,
#REQUIRED, and#FIXEDcases. - Internal general entity replacement.
- Local file-based external
SYSTEMsubset loading. - Local external general entity replacement in supported cases.
Known limitations:
- No HTTP/network retrieval for external DTDs/entities.
- No complete PUBLIC identifier or XML catalog resolution workflow.
- Parameter entities and external-subset semantics are not full XML conformance.
- Complex content-model grammar and all quantifier combinations are not guaranteed by fallback validation paths.
- DTD default-value materialization is limited.
- No built-in XSD validation.
- Recovery/conformance test helpers can mask parser gaps and must not be used as evidence of strict parsing.
When changing DTD code, update both focused tests in XmlDtdImplementedCases.cs/XmlExternalDtdSupport.cs and the DTD documentation if the support boundary changes.
The main ownership path for XML behavior is:
XmlTokenizerrecognizes lexical XML constructs.XmlDomBuilderconsumes tokens and controls tree state.XmlDomBuilder.ApplyValidation()setsXmlDocument.IsValidafter the tree is built.XmlParserexposes the builder through public synchronous/asynchronous APIs.
When debugging a behavior:
- If parsing throws before a DOM exists, inspect
XmlTokenizerandXmlParseErrorfirst. - If the DOM shape is wrong, inspect
XmlDomBuilderstate transitions and token consumption. - If
IsValidis wrong, inspect DOCTYPE parsing, DTD declarations,ApplyValidation, and recursive content/attribute checks. - If an entity is unresolved, inspect both tokenizer entity lookup and DTD declaration loading.
- If loading through a browsing context fails, inspect
XmlConfigurationExtensionsand document factory registration.
Prefer the smallest change at the controlling layer. Keep strict parsing and recovery parsing separate; do not make production parser behavior permissive just to satisfy a broad conformance fixture.
Use focused tests first, then the full suite:
dotnet test src/AngleSharp.Xml.Tests/AngleSharp.Xml.Tests.csproj \
--filter 'FullyQualifiedName~XmlDtdImplementedCases'
dotnet test src/AngleSharp.Xml.Tests/AngleSharp.Xml.Tests.csproj \
--filter 'FullyQualifiedName~XmlExternalDtdSupport'
dotnet test src/AngleSharp.Xml.Tests/AngleSharp.Xml.Tests.csproj -v qFor parser changes, include tests for:
- Strict well-formed input.
- Strict malformed input that must throw.
- Valid DTD input and invalid DTD input through
IsValid. - Internal and external entity behavior where relevant.
- Recovery mode only when recovery behavior is explicitly the subject.
Conformance fixture suites are broad and include historical XML test cases that depend on external resources, complex DTD features, or behavior not fully implemented in this repository. Treat ToXmlDocumentConformance and similar helpers as compatibility/recovery harnesses, not as a replacement for strict parser assertions.
- C# uses four spaces; project files use two spaces.
- Repository line endings are LF and files use UTF-8.
- Warnings are errors for the library build.
- Preserve existing public APIs and AngleSharp patterns.
- Avoid unrelated formatting or refactoring.
- Use explicit, descriptive variable names; follow the surrounding style.
- Keep comments concise and explanatory only where needed.
- Do not add license headers.
- Do not commit, reset, checkout, or create branches unless explicitly requested.
- Do not remove user changes from a dirty worktree.
- Keep generated
bin/,obj/,.fallout/, and test-result artifacts out of source changes unless the task explicitly concerns them.
- The test project uses
netstandard2.0for its library project reference even though the tests run onnet8.0. - Windows-only target frameworks are conditionally added based on
OS == Windows_NT; do not assume Linux can buildnet462/net472. - The build version comes from
CHANGELOG.md, not only the csproj version property. WithXml()is required for BrowsingContext XML/SVG loading; directXmlParserconstruction is separate.- XML entity names passed to the built-in provider include the trailing semicolon (
amp;, notamp). IsSuppressingErrorschanges control flow and can produce a non-null but structurally unreliable document.- A passing broad conformance helper test does not prove strict XML conformance.
- External DTD support is local-file-oriented and must not be described as network/catalog-aware.
- DTD
IsValidis not XSD validation and does not replace domain-specific validation. - The docs index and DTD support matrix should be updated when DTD behavior changes.
- Check
git status --shortand identify the nearest file/symbol/test. - Read the controlling code path and one neighboring test.
- State a falsifiable local hypothesis and choose the cheapest focused test.
- Make the smallest edit with the repository's existing style.
- Run the focused test immediately.
- Repair only the same local slice if it fails; do not broaden prematurely.
- Run the relevant fixture or project test suite.
- Run the full test suite when shared parser, tokenizer, DOM, DTD, or build behavior changed.
- Update docs and tests when public behavior or support boundaries change.
- Report exact validation commands and any remaining limitations.