5

Basically I am using:

from xml.etree import ElementTree as ET

path = 'C:\cool.xml'
et = ET.parse ( path )

But I am not sure how to get the root from et?

3 Answers 3

11

You probably want:

et.getroot()

Have a look at the official docs for ElementTree from the effbot site. Note that Python 2.5 (the first version of Python to include ElementTree out of the box) uses ElementTree 1.2, not the more recent 1.3. There aren't many differences, but just FYI in case.

Sign up to request clarification or add additional context in comments.

Comments

4
root = et.getroot()

I would recommend using lxml.etree instead of xml.etree.ElementTree, as lxml is faster and the interface is the same.

1 Comment

There is no syntactical difference?
2
root = et.getroot()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.