Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Python: How to Search for XML Elements

from xml.dom import minidom 
def findElement(xml_file, elem):
    xmldoc = minidom.parse(xml_file)
    myElem = xmldoc.getElementsByTagName(elem)

Python: Loading an XML Document

from xml.dom import minidom  
xmldoc = minidom.parse('c:/teste.xml')
print xmldoc
print xmldoc.toxml()

Python: How to Parse XML document from a URL

import urllib
xml_distant = urllib.urlopen('http://www.example.me/file.xml')
xmldoc = minidom.parse(xml_distant)
xml_distant.close()
print xmldoc.t

Python: Create a XML Document

from xml.dom import minidom
xml_content = "demo@gmail.comenvoi de msg"
xmldoc = minidom.parseString(xml_content)
print xmldoc.toxml()

Python: Processing XML with Regular Expressions

import re
regex = r'(w)'
xml_data = open('c:/teste.xml').read()
result = re.search(regex,xml_data)
if result:
   print result.group(1)

Python: How to get element by name

from xml.dom import minidom
xmldoc = minidom.parse('c:/test.xml')
email = xmldoc.getElementsByTagName('addr')[0].firstChild.data
print email
[/pyth

Python: How to read Microsoft Excel XML document

import sys
from xml.sax import saxutils, parse
class ExcelHandler(saxutils.DefaultHandler):
    def __init__(self):
        self.chars = [  ]

Python: Delete a node in a DOM tree

from xml.dom import minidom
xmldoc = minidom.parse('c:/test.xml')
doc_root = xmldoc.documentElement
etat=doc_root.removeChild(doc_root.childNod