pabigot / pyxb

Python XML Schema Bindings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Check for wildcard content happens when option RequireValidWhenParsing is set to False

AliceAlbano opened this issue · comments

I parsed a xml with option RequireValidWhenParsing set to False, and I got a StructuralBadDocumentError: cannot accept wildcard content

But if I set this option to True, i got no error at all.
In the code, I found this:

if not require_validation:
    if element_decl is not None:
        element_decl.setOrAppend(self, value)
        return self
    if self.__wildcardElements is not None:
        self._appendWildcardElement(value)
        return self
    raise pyxb.StructuralBadDocumentError(container=self, content=value)

This if condition seems very strange: the check should be when the validation is required i think?

No, that's correct. The body of that condition places the content without validation (e.g. allowed, ordering, or multiplicity checks), based on whether it's recognized as element or allowed as a wildcard. Validating placement uses the automaton which follows that test.

Disabling validation in PyXB is not a primary or supported use case, since the whole purpose of PyXB is to validate. In this case PyXB's found something that it doesn't recognize, and confirmed that things that aren't recognized aren't allowed, so it diagnoses the document as invalid. The alternative would be to silently discard the element, which I decided was even less helpful.