Skip to content

Added relaxed option#45

Open
frankarensmeier wants to merge 2 commits into
faassen:mainfrom
frankarensmeier:main
Open

Added relaxed option#45
frankarensmeier wants to merge 2 commits into
faassen:mainfrom
frankarensmeier:main

Conversation

@frankarensmeier

Copy link
Copy Markdown

Add ParseOptions to allow duplicate xml:id values

Some real-world XML documents (e.g. DocBook content management systems) contain duplicate xml:id attribute values. Currently xot unconditionally rejects these with ParseError::DuplicateId, which makes it impossible to process such documents even when the consumer doesn't rely on ID uniqueness.

This PR adds a ParseOptions struct that lets callers opt into relaxed parsing behavior:

let options = ParseOptions {
    allow_duplicate_ids: true,
};
let root = xot.parse_with_options(xml, &options)?;

When allow_duplicate_ids is true:

  • Duplicate xml:id values no longer produce an error
  • The first occurrence wins for [id()] lookups (matching Saxon's behavior)
  • The seen_ids set is still maintained to detect duplicates, but only the first node is inserted into id_nodes

When allow_duplicate_ids is false (the default), behavior is identical to today.

Add ParseOptions to allow duplicate xml:id values

Introduce a ParseOptions struct with an `allow_duplicate_ids` field
that controls whether duplicate xml:id values cause a DuplicateId
error (default) or are silently accepted with first-occurrence-wins
semantics for id() lookups.

New public API:
- ParseOptions { allow_duplicate_ids: bool }
- Xot::parse_with_options(xml, &ParseOptions)
- Xot::parse_with_span_info_and_options(xml, &ParseOptions)
- Xot::parse_fragment_with_span_info_and_options(xml, &ParseOptions)

Existing parse/parse_with_span_info/parse_fragment_with_span_info
methods are unchanged and continue to reject duplicates.
…_syntaxes warnings

Applied cargo fix suggestions to add <'_> to return types where elided
lifetimes were confusing. Fixes 12 warnings introduced by newer Rust.
@frankarensmeier frankarensmeier force-pushed the main branch 2 times, most recently from 976c384 to 5a936ad Compare May 4, 2026 13:22
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.

1 participant