Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: strict mode for parsing #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

barredterra
Copy link

@barredterra barredterra commented Dec 16, 2024

Resolves #51

Introduce a strict parsing mode which defaults to True. This maintains the current behavior of raising en error when an unknown element is encountered. If set to False, the parser ignores unknown elements.

Example:

Document.parse(samplexml)  # parses only known elements, raises TypeError otherwise
Document.parse(samplexml, strict=False)  # parses what it can, returns without errors

Implementation:

Since the TypeErrors are usually raised in the from_etree method, I added the strict parameter in all paths leading there.

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.

Parser should not fail on unknown elements
1 participant