def toElement()

in vmap_generation/vmap_xml/vmap.py [0:0]


    def toElement(self, doc):
        vmapElement = doc.createElementNS('http://www.iab.net/videosuite/vmap', 'vmap:VMAP')
        vmapElement.setAttribute("version", self.version)
        vmapElement.setAttribute("xmlns:vmap", "http://www.iab.net/videosuite/vmap")
        for adBreak in self.adBreaks:
            _type = adBreak.adSource["type"]
            adBreakElement = doc.createElementNS("http://www.iab.net/videosuite/vmap", "vmap:AdBreak")
            for key, value in adBreak.attributes.items():
                adBreakElement.setAttribute(key, value)
            vmapElement.appendChild(adBreakElement)

            adSourceElement = doc.createElementNS("http://www.iab.net/videosuite/vmap", "vmap:AdSource")
            adSourceElement.setAttribute("id", adBreak.adSource["_id"])
            adSourceElement.setAttribute("allowMultipleAds", adBreak.adSource["allow_mutiple_ads"])
            adSourceElement.setAttribute("followRedirects", adBreak.adSource["follow_redirects"])
            adBreakElement.appendChild(adSourceElement)
            
            adTypedElement = doc.createElementNS("http://www.iab.net/videosuite/vmap", "vmap:{type}".format(type=_type))
            for key, value in adBreak.adSource["attributes"].items():
                adTypedElement.setAttribute(key, value)
            adSourceElement.appendChild(adTypedElement)

            if _type == "VASTAdData":
                vastElement = adBreak.adSource["source"].toElement(doc)
                adTypedElement.appendChild(vastElement)
            elif _type == 'AdTagURI':
                adTypedElement.appendChild(doc.createCDATASection(adBreak.adSource["source"]))

            if len(adBreak.trackingEvents) > 0:
                trackingEventsElement = doc.createElementNS("http://www.iab.net/videosuite/vmap", "vmap:TrackingEvents")
                adBreakElement.appendChild(trackingEventsElement)
            for event in adBreak.trackingEvents:
                trackingElement = doc.createElementNS("http://www.iab.net/videosuite/vmap", "vmap:Tracking")
                trackingElement.setAttribute("event", event.event)
                trackingElement.appendChild(doc.createCDATASection(event.url))
                trackingEventsElement.appendChild(trackingElement)

        return vmapElement