Next / Previous / Contents / Shipman's homepage

15.3. AgeSexGroup.writeNode()

Translate the instance back to XML. The way the .long flag works is different from the rest of the attributes: in anticipation of later direct editing of the XML, we add a newline to the parent node's text content so that it will use paired tags “<form>...</form>” so that is easier to add other child content.

birdnotes.py
# - - -   A g e S e x G r o u p . w r i t e N o d e

    def writeNode(self, parent):
        """Translate self to XML.
        """
        #-- 1 --
        # [ if self.age is true ->
        #     parent  :=  parent with an rnc.AGE_A attribute (self.age)
        #   else -> I ]
        if  self.age:
            parent.attrib[rnc.AGE_A] = self.age

        #-- 2 --
        # [ simile ]
        if  self.sex:
            parent.attrib[rnc.SEX_A] = self.sex

        #-- 3 --
        if  self.q:
            parent.attrib[rnc.Q_A] = self.q

        #-- 4 --
        if  self.count:
            parent.attrib[rnc.COUNT_A] = self.count

        #-- 5 --
        if  self.fide:
            parent.attrib[rnc.FIDE_A] = self.fide

The “long flag” inserts a newline and four spaces as the text of the parent node. This will produce output that looks like this:

    <form ab6='...'>
    </form>
birdnotes.py
        #-- 6 --
        if  self.long:
            parent.text = (parent.text or '') + '\n    '