Skip to content

Add an opt-in check for a single document element - #1022

Closed
MaciejZet wants to merge 1 commit into
tafia:masterfrom
MaciejZet:fix/check-document
Closed

MaciejZet wants to merge 1 commit into
tafia:masterfrom
MaciejZet:fix/check-document

Conversation

@MaciejZet

Copy link
Copy Markdown

Summary

One slice of #848: a document has exactly one element.

Config::check_document stays off, so <a/><b/> and other fragments still parse. With the flag on, the reader returns Error::IllFormed for:

  • a second top-level element
  • text, CDATA, or a reference outside that element (whitespace around it is fine)
  • end of input with no element, including an XML declaration on its own

Comments and processing instructions around the element stay allowed. enable_all_checks still covers only the comment and end-name checks, so existing fragment callers are unchanged.

The rest of #848 is still open. This does not try to close it.

Test plan

  • cargo test --all-features --lib --tests
  • doctest on Config::check_document
  • cargo fmt -- --check

Fragments stay accepted unless Config::check_document is set. With the
check on, a second top-level element, character data outside the element,
or end of input with no element is ill-formed.

Refs tafia#848
@Mingun

Mingun commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

I prefer that such check would be performed by the quick-xml consumers.

@Mingun Mingun closed this Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants