How to use the elementpath.XPathContext function in elementpath

To help you get started, we’ve selected a few elementpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sissaschool / xmlschema / xmlschema / validators / elements.py View on Github external
def test(self, elem):
        try:
            return self.token.boolean_value(list(self.token.select(context=XPathContext(elem))))
        except (TypeError, ValueError):
            return False
github sissaschool / xmlschema / xmlschema / validators / assertions.py View on Github external
def __call__(self, elem, value=None, source=None, namespaces=None, **kwargs):
        if value is not None:
            self.parser.variables['value'] = self.base_type.text_decode(value)
        if not self.parser.is_schema_bound():
            self.parser.schema.bind_parser(self.parser)

        if source is None:
            context = XPathContext(root=elem)
        else:
            context = XPathContext(root=source.root, item=elem)

        default_namespace = self.parser.namespaces['']
        if namespaces and '' in namespaces:
            self.parser.namespaces[''] = namespaces['']

        try:
            if not self.token.evaluate(context.copy()):
                msg = "expression is not true with test path %r."
                yield XMLSchemaValidationError(self, obj=elem, reason=msg % self.path)
        except ElementPathError as err:
            yield XMLSchemaValidationError(self, obj=elem, reason=str(err))

        self.parser.namespaces[''] = default_namespace
github sissaschool / xmlschema / xmlschema / validators / assertions.py View on Github external
def __call__(self, elem, value=None, source=None, namespaces=None, **kwargs):
        if value is not None:
            self.parser.variables['value'] = self.base_type.text_decode(value)
        if not self.parser.is_schema_bound():
            self.parser.schema.bind_parser(self.parser)

        if source is None:
            context = XPathContext(root=elem)
        else:
            context = XPathContext(root=source.root, item=elem)

        default_namespace = self.parser.namespaces['']
        if namespaces and '' in namespaces:
            self.parser.namespaces[''] = namespaces['']

        try:
            if not self.token.evaluate(context.copy()):
                msg = "expression is not true with test path %r."
                yield XMLSchemaValidationError(self, obj=elem, reason=msg % self.path)
        except ElementPathError as err:
            yield XMLSchemaValidationError(self, obj=elem, reason=str(err))

        self.parser.namespaces[''] = default_namespace