Next / Previous / Contents / Shipman's homepage

36. Sox.doctype()

sox.py
# - - -   S o x . d o c t y p e

    def doctype(self, name, pubId=None, sysId=None):
        '''Write a DOCTYPE declaration.
        '''

There are four cases depending on the presence or absence of the two optional arguments.

pubIdsysIdOutput
NoNo <!DOCTYPE name>
NoYes <!DOCTYPE name SYSTEM "sysId">
YesNo <!DOCTYPE name PUBLIC "pubId">
YesYes <!DOCTYPE name PUBLIC "pubId" "sysId">

We'll deal with these cases by building a list pieceList with the various pieces, then concatenating them.

sox.py
        #-- 1
        # [ pieceList  :=  a list containing <!DOCTYPE name " ]
        pieceList = [ "<!DOCTYPE %s" % name ]

        #-- 2
        if pubId is None:
            if sysId is not None:
                pieceList.append(' SYSTEM "%s"' % sysId)
        elif sysId is None:
            pieceList.append(' PUBLIC "%s"' % pubId)
        else:
            pieceList.append(' PUBLIC "%s" "%s"' %
                             (pubId, sysId))

        #-- 3
        pieceList.append(">")

        #-- 4
        self.outFile.write(''.join(pieceList))