Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to retrieve the name attributes of each user node in python on the XML file below. For that, I looked for which library I could use and I came across ElementTree.
But testing some examples from the documentation I found below, it doesn't work on the XML file below.
https://docs.python.org/3/library/xm...ementtree.html
https://lxml.de/tutorial.html

XML
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns:test="http://test.com" xmlns:test2="test2.com" xmlns:xsi="http://test3.com">
<users>
    <user data-id="101">
        <nom>Zorro</nom>
        <metier>Danseur</metier>
    </user>
    <user data-id="102">
        <nom>Hulk</nom>
        <metier>Footballeur</metier>
    </user>
    <user data-id="103">
        <nom>Zidane</nom>
        <metier>Star</metier>
    </user>
    <user data-id="104">
        <nom>Beans</nom>
        <metier>Epicier</metier>
    </user>
    <user data-id="105">
        <nom>Batman</nom>
        <metier>Veterinaire</metier>
    </user>
    <user data-id="106">
        <nom>Spiderman</nom>
        <metier>Veterinaire</metier>
    </user>
</users>
</book>


What I have tried:

I did some tests in python and I think it's the book tag that makes it not work.
Could you show me the python code that allows to list all names of each user node?

Do you also have links to documentation on XML traversal in python and other libraries other than ElementTree?

Thanks.
Posted
Updated 1-Jan-23 13:03pm

1 solution

I'm not familiar with python, so I did a quick Google Search to see what information is out there: xml parsing in python - Google Search[^].

There is a lot out there to help you. This one caught my eye: XML parsing — The Hitchhiker's Guide to Python[^].

There are lots of other examples found using the search above.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900