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


Python XML.getiterator方法代码示例

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


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

示例1: parse_captions

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [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.getiterator('title'):
		start = title.get('start')
		ids = start.rfind(':')
		end = title.get('end')
		ide = end.rfind(':')
		output = output + str(i) + '\n'
		output = output + start[:ids] + ',' + start[ids+1:] + ' --> ' + end[:ide] + ',' + end[ide+1:] + '\n'
		output = output + title.text.replace('|','\n') + '\n\n'
		i += 1

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

示例2: parse_config

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [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.getiterator('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']
	rtmp_chunks = rtmp_url.split('/')

	return {
		'rtmp_url'  : rtmp_url,
		'rtmp_host' : rtmp_chunks[2],
		'rtmp_app'  : rtmp_chunks[3],
		'auth_url'  : params['auth'],
		'api_url' : params['api'],
		'categories_url' : params['categories'],
		'captions_url' : params['captions'],
	}
开发者ID:bencollerson,项目名称:python-iview,代码行数:28,代码来源:parser.py

示例3: parse_captions

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [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.getiterator('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:BenPhegan,项目名称:python-iview,代码行数:29,代码来源:parser.py

示例4: get_raw_text

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def get_raw_text(pthFile):
	"""
	gets a path to a file as an argument and returns a list containing
	the paragraphs of the word document file
	"""
	
	"""
	Constants used to iterate over the XML tree
	"""
	WORD_NAMESPACE = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'
	PARA = WORD_NAMESPACE + 'p'
	TEXT = WORD_NAMESPACE + 't'

	docWordDoc = zipfile.ZipFile(pthFile) #gets the documents of the word
	xmlContent = docWordDoc.read('word/document.xml') #access the xml file
	docWordDoc.close()
	treeXML = XML(xmlContent) #parses the xml content into a tree that will be further used to access the text

	lstParagraphs = [] #output list with the paragraphs of the text
	#now we proceed to extract the text from the tree
	#the idea is to iterate over the tree and 
	#for each node that contains text, substract it and add it to
	#the output
	for parParagraph in treeXML.getiterator(PARA):
		lstTexts = [nodElement.text
			    for nodElement in parParagraph.getiterator(TEXT)
			    if nodElement.text]
		if lstTexts:
			print lstTexts
			lstParagraphs.append(''.join(lstTexts))
		
	return lstParagraphs
开发者ID:JJLionHeart,项目名称:Tartin,代码行数:34,代码来源:wordReader.py

示例5: get_docx_text

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
 def get_docx_text(self, path):
     document = zipfile.ZipFile(path)
     xml_content = document.read('word/document.xml')
     tree = XML(xml_content)
     document.close()
     paragraphs = []
     for paragraph in tree.getiterator(para_tag):
         texts = [node.text for node in paragraph.getiterator(text_tag) if node.text]
         if texts:
             paragraphs.append(''.join(texts))
     return paragraphs
开发者ID:opendatakosovo,项目名称:112,代码行数:13,代码来源:parser.py

示例6: get_docx_text

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def get_docx_text(path):
    document = zipfile.ZipFile(path)
    xml_content = document.read("word/document.xml")
    document.close()
    tree = XML(xml_content)

    paragraphs = []
    for paragraph in tree.getiterator(PARA):
        texts = [node.text for node in paragraph.getiterator(TEXT) if node.text]
        if texts:
            paragraphs.append("".join(texts))
    return paragraphs
开发者ID:anastiel,项目名称:open-catalog-generator,代码行数:14,代码来源:word_to_JSON.py

示例7: get_docx_text

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def get_docx_text(path):
	"""
	Take the path of a docx file as argument, return the text in unicode
	in the form of a list.
	"""
	document = zipfile.ZipFile(path)
	xml_content = document.read('word/document.xml')
	document.close()
	tree = XML(xml_content)
 
	paragraphs = []
	for paragraph in tree.getiterator(PARA):
		texts = [node.text.encode('utf-8')
				 for node in paragraph.getiterator(TEXT)
				 if node.text]
		if texts:
			paragraphs.append(''.join(texts))
 
	return paragraphs



 
# def get_docx_text(path):
# 	"""
# 	Take the path of a docx file as argument, return the text in unicode
# 	in the form of a list.
# 	"""
# 	document = zipfile.ZipFile(path)
# 	xml_content = document.read('word/document.xml')
# 	document.close()
# 	tree = XML(xml_content)
 
# 	sections = []
# 	for section in tree.getiterator(SECT):

# 		paragraphs = []
# 		for paragraph in section.getiterator(PARA):
# 			print 'para'
# 			texts = [node.text.encode('utf-8')
# 					 for node in paragraph.getiterator(TEXT)
# 					 if node.text]
# 			if texts:
# 				paragraphs.append(''.join(texts))

# 		print str(paragraphs)

# 		if paragraphs:
# 			sections.append(''.join(paragraphs))

 
# 	return sections    
开发者ID:KODeKarnage,项目名称:Ratings_Note_Processor,代码行数:54,代码来源:RN_toolbag.py

示例8: read_docx

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def read_docx(file,document,path,trie):
	xml_content = document.read('word/document.xml')
	document.close()
	tree = XML(xml_content)
	paragraphs = ""
	for paragraph in tree.getiterator(PARA):
		texts=""
		for node in paragraph.getiterator(TEXT):
			if node.text:
				texts += node.text.replace('\u7460',"")
		if texts:
			paragraphs+=str(texts)
	#print(paragraphs)
	string_spilt(paragraphs,path,trie)
	trie.insert_doc_len(path,len(file)+len(paragraphs))
开发者ID:jackybaseline,项目名称:local_search,代码行数:17,代码来源:main.py

示例9: get_doc_text

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def get_doc_text(path):
    """
    Take the path of a docx or a dot file as argument, return the text in unicode.
    """
    if "docx" == path[-4:]:
        document = zipfile.ZipFile(path)
        xml_content = document.read('word/document.xml')
        document.close()
        tree = XML(xml_content)
    #print tree

        paragraphs = []
        for paragraph in tree.getiterator(PARA):
            texts = [node.text for node in paragraph.iter(TEXT) if node.text]
            if texts:
                paragraphs.append(''.join(texts))
                pass
            pass
    #print paragraphs
        return paragraphs
#        
    elif "odt" == path[-3:]:
        document = zipfile.ZipFile(path)
        xml_content = document.read('content.xml')
        document.close()
        doc = xml.dom.minidom.parseString(xml_content)
        print(" doc: ",doc)
        print("doc::end")
        #paras = doc.getElementsByTagName('text:span')
        #paras = doc.getElementsByTagName('text:p')
        #
        # we get here all elements Headers, text and table components: 
        #
        paras = doc.getElementsByTagName("*")
        print("I have ", len(paras), " paragraphs ")
        paragraphs = []
        for p in paras:
            for ch in p.childNodes:
                if ch.nodeType == ch.TEXT_NODE:
                    paragraphs.append(''.join(ch.wholeText))
                    pass
                pass
            pass
        print(paragraphs)
        return paragraphs
    else:
        print() 
        raise Warning("only docx and odt files are handled")    
开发者ID:apdimier,项目名称:Etumos,代码行数:50,代码来源:dotextract.py

示例10: get_docx_text

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def get_docx_text(path):
	"""	Take the path of a docx file as argument, return the text in unicode."""
	document = zipfile.ZipFile(path)
	xml_content = document.read('word/document.xml')
	document.close()
	tree = XML(xml_content)
 
	paragraphs = []
	for paragraph in tree.getiterator(PARA):
		texts = [node.text
				for node in paragraph.getiterator(TEXT)
				if node.text]
		if texts:
			paragraphs.append(''.join(texts))
 
	return '\n\n'.join(paragraphs) 
开发者ID:DewarM,项目名称:cvParser,代码行数:18,代码来源:doc2text.py

示例11: docx_do_docx

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def docx_do_docx(azip, afile):
    word_namespace = "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}"
    par = word_namespace + "p"
    txt = word_namespace + "t"

    xml_content = azip.read("word/document.xml")
    tree = XML(xml_content)

    paragraphs = []
    for paragraph in tree.getiterator(par):
        texts = [node.text for node in paragraph.getiterator(txt) if node.text]
        if texts:
            paragraphs.append("".join(texts))

    text = "\n\n".join(paragraphs)
    text_do_data(text, afile)
开发者ID:nmnz,项目名称:blueflower,代码行数:18,代码来源:docx.py

示例12: docx_do_docx

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def docx_do_docx(azip, afile):
    namespace = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'
    par = namespace + 'p'
    txt = namespace + 't'

    xml_content = azip.read('word/document.xml')
    tree = XML(xml_content)

    paragraphs = []
    for paragraph in tree.getiterator(par):
        texts = [node.text for node in paragraph.getiterator(txt)
                 if node.text]
        if texts:
            paragraphs.append(''.join(texts))

    text = '\n\n'.join(paragraphs)
    text_do_data(text, afile)
开发者ID:rjmolesa,项目名称:blueflower,代码行数:19,代码来源:docx.py

示例13: getContents

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
    def getContents(self):
        """
        Just read the paragraphs from an XML file.
        """

        xml_content = self.my_docx.read('word/document.xml')
        self.my_docx.close()
        tree = XML(xml_content)

        self.text_in_paragraphs = []
        for paragraph in tree.getiterator(PARA):
            texts = [node.text for node in paragraph.iter(TEXT) if node.text]
            if texts:
                self.text_in_paragraphs.append(''.join(texts))
                pass
            pass
    #print paragraphs
        return self.text_in_paragraphs
开发者ID:apdimier,项目名称:Etumos,代码行数:20,代码来源:dotextract.py

示例14: parse_captions

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def parse_captions(soup):
	"""	Converts custom iView captions into SRT format, usable in most
		decent media players.
	"""
	xml = XML(soup)

	output = ''

	i = 1
	for title in xml.getiterator('title'):
		start = title.get('start')
		ids = start.rfind(':')
		end = title.get('end')
		ide = end.rfind(':')
		output = output + str(i) + '\n'
		output = output + start[:ids] + ',' + start[ids+1:] + ' --> ' + end[:ide] + ',' + end[ide+1:] + '\n'
		output = output + title.text.replace('|','\n') + '\n\n'
		i += 1

	return output
开发者ID:bencollerson,项目名称:python-iview,代码行数:22,代码来源:parser.py

示例15: get_docx_text

# 需要导入模块: from xml.etree.cElementTree import XML [as 别名]
# 或者: from xml.etree.cElementTree.XML import getiterator [as 别名]
def get_docx_text(path):
    """
    Take the path of a docx file as argument, return the text in unicode.
    """
    WORD_NAMESPACE = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'   # formatting for docx
    PARA = WORD_NAMESPACE + 'p'                                                         # formatting for paragraphs
    TEXT = WORD_NAMESPACE + 't'                                                         # formatting for text
    document = zipfile.ZipFile(path)                                                    # the unzipped document path
    xml_content = document.read('word/document.xml')                                    # location of the primary xml document
    document.close()                                                                    # closes the document
    tree = XML(xml_content)                                                             # splits the xl into a tree

    paragraphs = []                                                                     # a list of the paragraphs
    for paragraph in tree.getiterator(PARA):                                            # for every new paragraph in the tree
        texts = [node.text                                                              # the text is the text node in the tree
                 for node in paragraph.getiterator(TEXT)                                # 
                 if node.text]                                                          # if the node is text, add it to the text list
        if texts:                                                                       # if a text is found,
            paragraphs.append(''.join(texts))                                           # add it to the paragraphs list
    #return('\n\n'.join(paragraphs))
    return(paragraphs)                                                                  # return the paragra
开发者ID:MrSprinklez,项目名称:flash_cards,代码行数:23,代码来源:document_import.py


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