-1

In my python code I am using the root = ElementTree.parse(known_file_path).getroot() method to return an XML tree. I know the location of known_file_path (obviously), however, I cannot seem to determine where the "root" XML file is located on my filesystem. When I run ElementTree.dump(root) method I am able to see the contents of the XML file with all of the tags and information, and I just want to modify this file. However, I do not know where this file is stored, and I cannot seem to figure out how to print out the path to this file. Since Python is printing out tags and data, I should be able to find this XML file somewhere in my file system, right?

2 Answers2

0

From the documentation

xml.etree.ElementTree.dump(elem)
Writes an element tree or element structure to sys.stdout

So - dump() doesn't do what you expected it to do... For that you need

tree.write('output.xml')
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
0

You are under a misconception about what root means here. It has nothing to do with a filesystem; it has to do with document structure.

XML and document structure

The root (root node) of an XML document is the parent of the root element in an XML document.

See also What is the difference between root node, root element and document element in XML?

Python and filesystems

If you want to get the filesystem path of an XML (or any other) file, see How to get an absolute file path in Python.

kjhughes
  • 106,133
  • 27
  • 181
  • 240