0

I'm parsing a really simple .xml file with this snippet

import xml.etree.ElementTree as etree
tree = etree.parse('/home/user/dummy.xml')
print(tree.getroot())

the output is

<Element 'doc' at 0x1d2f090>

which is correct, but I was expecting something cleaner and as simple as

doc

is this the normal output ? How I can clean this ?

I'm using Python 3.x


the dummy.xml file

<?xml version="1.0"?>
<doc>
    <branch name="testing" hash="1cdf045c">
        text,source
    </branch>
    <branch name="release01" hash="f200013e">
        <sub-branch name="subrelease01">
            xml,sgml
        </sub-branch>
    </branch>
    <branch name="invalid">
    </branch>
</doc>

1 Answer 1

1

Yes, that's the default output for an Element. If you want just the tag, try:

print(tree.getroot().tag)
Sign up to request clarification or add additional context in comments.

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.