What's the best way to parse XML in Python?

8 Replies, 1706 Views

Honestly, if you’re just reading and tweaking XML, `minidom` might be overkill. It’s old-school and verbose.

Stick with `ElementTree` like others said. Here’s how you can modify and save:
```python
tree = ET.parse('data.xml')
root = tree.getroot()
root[0].text = "new value" # change something
tree.write('updated.xml')
```
Boom, done. No need to complicate things.

For more advanced stuff, maybe look into `xmltodict` if you prefer working with dictionaries.

Messages In This Thread



Users browsing this thread: 1 Guest(s)