예제 #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):
     """
     :param xml: the etree.Element to search in
     :param namespace: not used yet
     :rtype: as defined by ``self.field_type``
     """
     match = xpath_finder.find_all(xml, self.xpath, namespace)
     if len(match) > 1:
         raise MultipleNodesReturnedException
     if len(match) == 1:
         return self.field_type(xml=match[0])
     return self._default
예제 #3
0
 def parse(self, xml, namespace):
     """
     :param xml: the etree.Element to search in
     :param namespace: not used yet
     :rtype: as defined by ``self.field_type``
     """
     match = xpath_finder.find_all(xml, self.xpath, namespace)
     if len(match) > 1:
         raise MultipleNodesReturnedException
     if len(match) == 1:
         return self.field_type(xml=match[0])
     return self._default
예제 #4
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