I've searched for the definition of a "node" in a programming language and I am still finding it hard to understand.
Could anyone advice me in simple, layman's terms:
What is a node?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityI've searched for the definition of a "node" in a programming language and I am still finding it hard to understand.
Could anyone advice me in simple, layman's terms:
What is a node?
Etymologically, a "node" is a "knot": think of a fisherman's net as "holes tied together with string", and then nodes are where the string is knotted. The term comes from graph theory in mathematics. If you think of a graph as a collection of points connected to each other by lines ("arcs"), then the points are called nodes. A tree is a special case of a graph in which a node can only have one "upwards" arc (to its "parent"). The DOM models a document as a tree: documents have a hierarchic structure in which sections contains sections contain sections, and a tree is a graph-theoretic representation of a hierarchy. So the parts of a document - the sections - are represented by nodes in the tree.
In the context of an SGML language where DOM is typically used (i.e. HTML, XML), a node is the smallest piece of text that has semantic meaning. Nodes are arranged in a tree structure, with the document as the root node. Each node can have zero or more children.
There are several types of nodes:
<html>
tag). This is done so it can contain metadata such as the DOCTYPE.<div>
or <MyXmlElement>
. Elements can have subnodes, including attributes and other elements.class
specifier: <div class="SomeCssClass">
<div>This CDATA is a child of the div element.</div>
You can safely compare it to a map of a subway system, e.g. the London Underground:
(http://it.wikipedia.org/wiki/Mappa_della_metropolitana_di_Londra)
A node is a stop, an edge is the connection between stations. That's about it with general graphs. However, there are special graphs with more, interesting properties, like Trees:
(https://hbfs.wordpress.com/2013/05/14/average-node-depth-in-a-full-tree/)
Nodes in a tree are either (a) the root (think <html>) or (b) have exactly one parent. They may also have one or many children nodes, which have them as a parent, so we get exactly one path to the root for every node in the graph.
The DOM is a tree.
The Node object represents a single node in the document tree.
A node can be an element node, an attribute node, a text node, or any other of the node types explained in the Node Types chapter.