# - - - R a n k . w r i t e X M L
def writeXML ( self, parent ):
'''Generate an XML representation of self.
'''
The XML for a rank has four attributes plus content:
rnc.CODE_A is the rank code.
rnc.OPTIONAL_A has the value 1 only when
the rank is optional.
rnc.DIGITS_A is the number of digits this
rank contributes to the taxonomic key.
rnc.DEPTH_A is the rank's depth within
the hierarchy.
The text content is the rank's name.
#-- 1 --
# [ attributes := a dictionary of the attribute names
# and values for self ]
attributes = {
rnc.CODE_A: self.code,
rnc.DIGITS_A: str(self.keyLen),
rnc.DEPTH_A: str(self.depth) }
if not self.required:
attributes[rnc.OPTIONAL_A] = '1'
#-- 2 --
# [ parent := parent with a new rnc.RANK_N element added
# with attributes (attributes) and content
# self.name ]
parent.append ( E ( rnc.RANK_N, attributes, self.name ) )