当前位置: 首页>>代码示例>>Python>>正文


Python XML.iter方法代码示例

本文整理汇总了Python中xml.etree.cElementTree.XML.iter方法的典型用法代码示例。如果您正苦于以下问题:Python XML.iter方法的具体用法?Python XML.iter怎么用?Python XML.iter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml.etree.cElementTree.XML的用法示例。


在下文中一共展示了XML.iter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_config

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import iter [as 别名]
def parse_config(soup):
    """There are lots of goodies in the config we get back from the ABC.
    In particular, it gives us the URLs of all the other XML data we
    need.
    """

    xml = XML(soup)
    params = dict()
    for param in xml.iter('param'):
        params.setdefault(param.get('name'), param.get('value'))

    # should look like "rtmp://cp53909.edgefcs.net/ondemand"
    # Looks like the ABC don't always include this field.
    # If not included, that's okay -- ABC usually gives us the server in the auth result as well.
    rtmp_url = params['server_streaming']
    categories_url = params['categories']

    params.update({
        'rtmp_url'  : rtmp_url,
        'auth_url'  : params['auth'],
        'api_url' : params['api'],
        'categories_url' : categories_url,
        'captions_url' : params['captions'],
    })
    return params
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2: parse_captions

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import iter [as 别名]
def parse_captions(soup):
    """Converts custom iView captions into SRT format, usable in most
    decent media players.
    """
    
    # Horrible hack to escape literal ampersands, which have been seen in
    # some captions XML. Inspired by
    # http://stackoverflow.com/questions/6088760/fix-invalid-xml-with-ampersands-in-python
    if b"<![CDATA[" not in soup:  # Not seen, but be future proof
        soup = re.sub(b"&(?![#\w]+;)", b"&amp;", soup)
    
    xml = XML(soup)

    output = ''

    i = 1
    for title in xml.iter('title'):
        start = title.get('start')
        (start, startfract) = start.rsplit(':', 1)
        end = title.get('end')
        (end, endfract) = end.rsplit(':', 1)
        output = output + '{}\n'.format(i)
        output = output + '{},{:0<3.3} --> {},{:0<3.3}\n'.format(start, startfract, end, endfract)
        output = output + title.text.replace('|','\n') + '\n\n'
        i += 1

    return output
开发者ID:,项目名称:,代码行数:29,代码来源:

示例3: get_docx_text

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import iter [as 别名]
def get_docx_text(path):
    #use white-space: pre CSS
    """
    Take the path of a docx file as argument, return the formatted text.
    """
    document = zipfile.ZipFile(path)
    xml_content = document.read('word/document.xml')
    document.close()
    tree = XML(xml_content)
    
    #elements = list()
    styleAdditions = list()
    elementString = ["<article>"]
	
    for paragraph in tree.iter(PARA):
        """for paraStyleElement in paragraph.find(PARAPROPS).iter():
            if paraStyleElement =="""
		
		#JUSTIFICATION
        justificationInfo = paragraph.find(PARAPROPS).find(justification).attrib[WORD_NAMESPACE+"val"]
        if justificationInfo != "left" and justificationInfo != "both":
            styleAdditions.append("text-align:"+justificationInfo+";")
        elif justificationInfo == "both":
            styleAdditions.append("text-align:justify;")
		
		#INDENT
        if paragraph.find(PARAPROPS).find(indent):
            indentInfo = dict()
            for attribKey in paragraph.find(PARAPROPS).find(indent).attrib:
                if attribKey == WORD_NAMESPACE +"hanging":
                    indentInfo["hanging"] = (float(paragraph.find(PARAPROPS).find(indent).attrib[attribKey])/20)
                if attribKey == WORD_NAMESPACE +"end" or attribKey == WORD_NAMESPACE +"right":
                    indentInfo["right"] = (float(paragraph.find(PARAPROPS).find(indent).attrib[attribKey])/20)
                if attribKey == WORD_NAMESPACE +"start" or attribKey == WORD_NAMESPACE +"left":
                   indentInfo["left"] = (float(paragraph.find(PARAPROPS).find(indent).attrib[attribKey])/20)
            for key in indentInfo:
                if key == "hanging":
                    styleAdditions.append("margin-top:"+str(indentInfo[key])+";")
                if key == "right" or key == "end":
                    styleAdditions.append("margin-right:"+str(indentInfo[key])+";")
                if key == "left" or key == "start":
                    styleAdditions.append("margin-left:"+str(indentInfo[key])+";")
                #left => start, right => end, hanging
				
		#BACKGROUND COLOURING
        if paragraph.find(PARAPROPS).find(shade):
                if paragraph.find(PARAPROPS).find(shade).attrib[WORD_NAMESPACE +"fill"] != "auto":
                    styleAdditions.append("background-color: #"+paragraph.find(PARAPROPS).find(shade).attrib["fill"]+";")
                
		#BORDERS
        if paragraph.find(PARAPROPS).find(paraBorders):
            for sideElement in paragraph.find(PARAPROPS).find(paraBorders).iter():
                pass
                if sideElement != WORD_NAMESPACE + "between":
                    styleAdditions.append("border-style:"+borderTypes[sideElement.attrib["val"]])
                        
		#GET ALL THE TEXT, FIX TO PUT TEXT INTO ITS HTML ELEMENT
        paragraphText = [element.text for element in paragraph.iter(TEXT) if element.text] #make a list comprehension of styles to match
        if not paragraphText:
            if paragraph.iter(shdBreak):            
                for shadow in paragraph.iter(shdBreak): #bloody generator making me use a for loop for one element
                    if shadow.attrib[WORD_NAMESPACE+"fill"] == "auto":
                        for element in paragraph.iter(fontSize):
                            breakSize = str(float(element.attrib[WORD_NAMESPACE+"val"])/2) #gets a dict of fontSize element attributes, then gets the value representing font size, in points
                            break
                        styleAdditions.append("min-height:"+breakSize+"pt;") #why not em? ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION
                        styleAdditions.append("margin:0;")
                    break
        else:
            elementString.append("<p")
            elementString.append(' style="')
            #elementString.append("white-space:pre-wrap;word-wrap:break-word;")
            for style in styleAdditions:
                elementString.append(style)
            if ''.join(elementString)[-1:] != ";":
                elementString.append(";")
            
            elementString.append('"')
            elementString.append(">")
            elementString.append("</p>\n")
            styleAdditions = list()
        """texts = [node.text
                 for node in paragraph.iter(TEXT)
                 if node.text]
        if texts:
            elements.append(''.join(texts))"""
    elementString.append("</article>")
    return ''.join(elementString)
开发者ID:Kunskaparen,项目名称:DOCX-to-HTML-converter,代码行数:90,代码来源:Docx+to+HTML.py


注:本文中的xml.etree.cElementTree.XML.iter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。