About 425,000 results
Open links in new tab
  1. How to read xml file using python? - Stack Overflow

    Aug 5, 2019 · I strongly advice against using xml.dom.minidom.Unless you have a very specific need to work with the very minimal and basic W3C DOM API, you want to be using the xml.etree.ElementTree API instead.

  2. python - How can I parse XML and get instances of a particular …

    try: import cElementTree as ET except ImportError: try: # Python 2.5 need to import a different module import xml.etree.cElementTree as ET except ImportError: exit_err("Failed to import cElementTree from any known place") def find_in_tree(tree, node): found = tree.find(node) if found == None: print "No %s in file" % node found = [] return found ...

  3. Reading XML file and fetching its attributes value in Python

    Sep 6, 2012 · parser = etree.XMLParser(recover=True) tree = etree.parse('your xml file', parser) I used this recently and it worked for me, you can try and see but in case you need to do any more complecated xml data extractions, you can take a look at this code i wrote for some project handling complex xml data extractions.

  4. Extracting text from XML using python - Stack Overflow

    Oct 7, 2011 · Learn how to extract text from XML using Python with examples and solutions shared by the Stack Overflow community.

  5. How to read data from xml file in python - Stack Overflow

    Dec 3, 2019 · When you run find on a text string, it will only search for elements at the root level. You can instead use xpath queries within find to search for any element within the doc:

  6. What is the fastest way to parse large XML docs in Python?

    [EDIT]This is because the (fast) C code has to invoke the python interpreter which is just not as fast as C. Basically, you're using the C code to read the file (fast) and then build the DOM in Python (slow).[/EDIT] Try to use xml.etree.ElementTree which is implemented 100% in C and which can parse XML without any callbacks to python code.

  7. Creating a simple XML file using python - Stack Overflow

    Aug 31, 2010 · The parameter file, however, also has the position number in the corresponding input (csv) file where the data will be taken from. This way, if there's any changes to the position of the data coming in from the input file, the program doesn't change; it dynamically works out the data field position from the appropriate tag in the parameter file.

  8. xml - Reading local file with lxml -Python - Stack Overflow

    Aug 23, 2021 · I have what I thought was very basic code to read an xml file into Python. But I'm baffled that I'm running into issues. I thought this code should work: from lxml import etree parser = etree.XMLParser(ns_clean=True, recover=True) tree = etree.parse('file.xml', parser) #root = tree.getroot() However, I get this issue:

  9. Parsing XML using Python ElementTree - Stack Overflow

    Nov 14, 2017 · We can import this data by reading from a file: import xml.etree.ElementTree as ET tree = ET.parse('country_data.xml') root = tree.getroot() Or directly from a string:

  10. How to get value from XML Tag in Python? - Stack Overflow

    Jul 7, 2014 · import codecs documentID = {} group = {} myfile = codecs.open("file.xml", mode = 'r', encoding = "utf8") for line in myfile: line = line.strip() #get id from tags #get title from tag #store in documentID #get group name and document reference

Refresh