Пример #1
0
    def parse(self, xml, namespace):
        """
        Find all nodes matching the xpath expression and create objects from each the matched node.

        If ``order_by`` has been defined then the resulting list will be ordered.

        :param xml: the etree.Element to search in
        :param namespace: not used yet
        :rtype: as defined by ``self.field_type``
        """
        matches = xpath_finder.find_all(xml, self.xpath, namespace)

        if BaseField not in self.field_type.__bases__:
            results = [self.field_type(xml=match) for match in matches]
        else:
            field = self.field_type(xpath='.')
            results = [
                field.parse(xpath_finder.domify(match), namespace)
                for match in matches
            ]
        if self.order_by:
            from operator import attrgetter

            results.sort(key=attrgetter(self.order_by))
        return results
Пример #2
0
    def parse(self, xml, namespace):
        """
        Find all nodes matching the xpath expression and create objects from each the matched node.

        If ``order_by`` has been defined then the resulting list will be ordered.

        :param xml: the etree.Element to search in
        :param namespace: not used yet
        :rtype: as defined by ``self.field_type``
        """
        matches = xpath_finder.find_all(xml, self.xpath, namespace)

        if BaseField not in self.field_type.__bases__:
            results = [self.field_type(xml=match) for match in matches]
        else:
            field = self.field_type(xpath='.')
            results = [field.parse(xpath_finder.domify(match), namespace) for match in matches]
        if self.order_by:
            from operator import attrgetter

            results.sort(key=attrgetter(self.order_by))
        return results
Пример #3
0
 def _get_tree(self):
     if self._dom is None:
         self._dom = xpath_finder.domify(self._get_xml())
     return self._dom
Пример #4
0
 def _get_tree(self):
     if self._dom is None:
         self._dom = xpath_finder.domify(self._get_xml())
     return self._dom