Next / Previous / Contents / Shipman's homepage

12.7. BirdForm.readNode() (static method)

As discussed in the introduction to Section 12, “class BirdForm: Notes for one kind of bird”, the translation of XML into an internal data structure does not strictly follow the structure of the XML: a form element with no floc children will be represented as a BirdForm instance with one Sighting instance, while if there are floc children, each of them will be converted to one Sighting instance.

This method requires a txny instance that defines the taxonomy of birds, and also the parent dayNotes instance so that it can check the validity of any location codes used.
# - - -   B i r d F o r m . r e a d N o d e

    def readNode(txny, dayNotes, node):
        """Convert from XML

The first step is to extract the parts of the form element: the taxon-group attributes, the optional loc-group pattern (which includes child loc-detail elements as well as attributes), and the various sighting-notes child elements. See Section 12.8, “BirdForm.getTaxonGroup() (static method)”, which also builds the basic BirdForm instance.
        #-- 1 --
        # [ if node's taxon-group defines a kind of bird valid
        #   in txny ->
        #     dayNotes  :=  a BirdForm instance with parent dayNotes
        #         made from node's taxon-group
        #     birdForm  :=  that instance
        #   else -> raise IOError ]
            birdForm = BirdForm.getTaxonGroup(txny, dayNotes, node)
        except KeyError as x:
            raise IOError(str(x))

At this point we determine whether there any floc children or not.
        #-- 2 --
        # [ flocList  :=  node's rnc.FLOC_N children as et.Element
        #                 instances ]
        flocList = node.xpath(rnc.FLOC_N)

At this point, if flocList is empty, this is the single-sighting case; otherwise it is the multi-sighting case.
        #-- 3 --
        # [ if flocList is empty ->
        #     birdForm  :=  birdForm with a single Sighting child
        #         added, made from node's age-sex-group, loc-group,
        #         and sighting-notes content
        #   else ->
        #     birdForm  :=  birdForm with loc-group and sighting-notes
        #         added from node, and Sighting children added, made
        #         from the elements of flocList ]
        if  len(flocList) == 0:
            birdForm.singleSighting(dayNotes, node)
            birdForm.multiSighting(dayNotes, node, flocList)

        #-- 4 --
        return birdForm