zoukankan      html  css  js  c++  java
  • Python 解析XML

    <text >
        
    <font size="86" spacing="17" />
        率誕詭不經唐元奘法師遊西域十有七年撰
    </text>
    <text >
        率誕詭不經唐元奘法師遊西域十有七年撰
    </text>
    import xml.etree.ElementTree

    tree
    =xml.etree.ElementTree.ElementTree(file="e:\\Python\\1.xml")
    elem
    =tree.getroot()
    file
    =open("e:\\a.txt",'w')
    for a in elem.getiterator("text"):
        
    #print len(a._children)
        if len(a._children)>0:       
            
    for node in a:          
                
    if node.tail<> None:
                    node.tail.encode(
    'utf-8')
                    file.write(node.tail.encode(
    'utf-8'))
                
    #print xml.etree.ElementTree.iselement(node)
        else:
            
    if a.text<>None:
                file.write(a.text.encode(
    'utf-8'))
  • 相关阅读:
    iOS的文字自适应
    指向指针的指针
    NSString的创建
    Foundation-常用结构体
    Foundation summary
    成员变量补充
    Block^
    Protocol
    Category-分类
    李明杰要在广州开课啦
  • 原文地址:https://www.cnblogs.com/warrior/p/1510714.html
Copyright © 2011-2022 走看看