Next / Previous / Contents / Shipman's homepage

19.10. Taxon.__writeXMLNode(): Write one node

nomcompile3
# - - -   T a x o n . _ _ w r i t e X M L N o d e

    def __writeXMLNode ( self, parent ):
        '''Build the XML node for one taxon.

          [ parent is an et.Element ->
              parent  :=  parent with a new rnc.TAXON_N element added
                          that represents self
              node  :=  that new element ]
        '''

First we build a dictionary of attribute values for the taxon element. The rank code, scientific name, and taxonomic key are always present. The status code is present only if the status is not normal. The bird code is present only if the taxon has a standard code.

nomcompile3
        #-- 1 --
        # [ attribs  :=  a new dictionary relating rnc.RANK_A
        #       to self.rank.code; rnc.SCI_A to self.sci; and
        #       rnc.TX_KEY_A to self's taxonomic key ]
        attribs = { rnc.RANK_A: self.rank.code,
                    rnc.SCI_A: self.sci,
                    rnc.TX_KEY_A: self.txKey }

        #-- 2 --
        if self.status != STATUS_NORMAL:
            attribs[rnc.STATUS_A] = self.status

        #-- 3 --
        # [ if self has a standard abbreviation ->
        #     attribs[rnc.STD_ABBR_A]  :=  that abbreviation
        #   else -> I ]
        stdAbbr = self.abbr()
        if stdAbbr is not None:
            attribs[rnc.STD_ABBR_A] = stdAbbr

        #-- 4 --
        # [ parent  :=  parent with a new rnc.TAXON_N element added
        #               with attributes (attribs)
        #   node  :=  that new element ]
        node = E ( rnc.TAXON_N, attribs )
        parent.append ( node )

The English name is added as a child element.

nomcompile3
        #-- 5 --
        # [ node  :=  node with a new rnc.ENG_N element added
        #             whose content is sci.eng ]
        node.append ( E ( rnc.ENG_N, self.eng ) )

        #-- 6 --
        return node