Wednesday, July 18, 2018

How do you parse an XML document using Python 3.70b2?

Let us start with an XML Document. Here is my XML Document saved to my computer as MyStudents.xml.


XMLParsing_0

Launch Python 3.7.0b5(x64bit) and do an import using the xml.etree.ElementTree module by importing it like,



XMLParsing_1

>>> import xml.etree.ElementTree as ET


Now you can use ET as shown here:

XMLParsing_2

Now you can get the 'root' of XML Document as in:


XMLParsing_3.jpg

You use the tag attribute of the root to get the tag.

The 'root' has children which are the four students with their ID's.

You can get all of the children as shown in the code shown below.


How is XML Documents parsed in R?
Read here.

Also here.


Parsing using JSON:
http://hodentekhelp.blogspot.com/2014/11/how-do-you-work-with-javascript-object.html

No comments: