Showing posts with label Parsing. Show all posts
Showing posts with label Parsing. Show all posts

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

Friday, April 15, 2016

What is DOM as related to the WEB?

DOM stands for Document Object Model. It is what the User Agent (for example a browser) produces in memory when it encounters an HTML Document .
An HTML document is really a text file with mark ups (using tags). Here is an example:
<html>
<head>
<title>About Me</title>
</head>
<body>
<h1>My origins</h1>
</body>
</html>

This is a tree of elements and some text.
The element looks like this:
 <element></element>

In the html document above, the elements are: <html></html><br /><head></head><br /><title></title><br /><body></body> 
The <html></html> elements contains the rest of the elements.The <head></head> element has the <title></title> element The <title></title>just contains a string

The <body></body> can contain many more elements.The above tree is how it would be seen by the browser to create a tree, the DOM tree or simply the tree.
The DOM tree not including the spaces and carriage returns is simply this:

In a practical example like a single page mobile app (which also follows the same principles asweb page) like this one in Intel the document may have a slightly different look, but the emulating browser as well as the device browser would evaluate the document based on this DOM tree shown here.