The Document Object Model (DOM) is a programming interface for HTML and XML(Extensible markup language) documents. It defines the logical structure of documents and the way a document is accessed and manipulated.
Parsing XML with DOM APIs in python is pretty simple. For the purpose of example we will create a sample XML document (sample.xml) as below:
Now, let’s parse the above XML using python. The below code demonstrates the process,
GeeksForGeeks Company id:1, name: Amar Pandey, salary:8.5 LPA id:2, name: Akbar Khan, salary:6.5 LPA id:3, name: Anthony Walter, salary:3.2 LPA
The same can also be done using a user-defined function as shown in the code below:
Company Name : GeeksForGeeks Company id:1, name:Amar Pandey, salary:8.5 LPA id:2, name:Akbhar Khan, salary:6.5 LPA id:3, name:Anthony Walter, salary:3.2 LPA
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- XML parsing in Python
- Exposing ML/DL Models as REST APIs
- Command-Line Option and Argument Parsing using argparse in Python
- Argparse VS Docopt VS Click - Comparing Python Command-Line Parsing Libraries
- Parsing PDFs in Python with Tika
- Parsing and Processing URL using Python - Regex
- NLP | Partial parsing with Regex
- Pandas | Parsing JSON Dataset
- Create XML Documents using Python
- How to Parse and Modify XML in Python?
- Python - JSON to XML
- Python - XML to JSON
- Serialize Python dictionary to XML
- Reading and Writing XML Files in Python
- Modify XML files with Python
- Python IMDbPY – Series Information in XML format
- Python IMDbPY – Company Information in XML format
- Python IMDbPY – Person Information in XML format
- Python IMDbPY – Movies Information in XML format
- Python IMDbPY – Getting Series Countries as XML
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.