Next / Previous / Contents / Shipman's homepage

28. Sox._startTag(): Write a start tag

sox.py
# - - -   S o x . _ s t a r t T a g

    def _startTag(self, uTag, attribs):
        '''Write a start tag to the output.

          [ (uTag is a unicode xml-name) and
            (attribs is a dict with its keys unicode xml-names) ->
              self.outFile  +:=  an XML start tag with name (uTag)
                  and attributes from (attribs), if any ]
        '''

See Section 24, “Sox._buildAttrs(): Build XML attributes from a dictionary” for the logic that converts an attribute dictionary into the XML form “name="value" ...”. That method's return value has a leading space if there are any attributes; this is necessary to separate it from the tag. If there are no attributes, however, it returns an empty string, so you don't get tags like <foo >.

sox.py
        #-- 1
        self.outFile.write("<%s%s>" %
            (uTag.encode('utf-8'), self._buildAttrs(attribs)))