Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Element node and Text Node

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE people SYSTEM "validator.dtd">

<people>
    <student>
        <name>John</name>
        <course>Computer Technology</course>
        <semester>6</semester>
        <scheme>E</scheme>
    </student>

    <student>
        <name>Foo</name>
        <course>Industrial Electronics</course>
        <semester>6</semester>
        <scheme>E</scheme>
    </student>
</people>  

In simple XML language <open-tag> data </open-tag> is an element.
As per my XML above, <student> ... </student> is an element and so are the other tags.

In DOM parsing, there is an Element node and a Text node. Referring to the book I am using, <student> is an Element node and <name>, <course> and the other nested tags are Text nodes.

So, if I am understanding DOM properly, all the outer tags are Elements and the tags that contain the actual data are Text nodes ?

like image 658
An SO User Avatar asked Apr 10 '13 08:04

An SO User


People also ask

What is the difference between element and node?

So, in a nutshell, a node is any DOM object. An element is one specific type of node as there are many other types of nodes (text nodes, comment nodes, document nodes, etc...). The DOM consists of a hierarchy of nodes where each node can have a parent, a list of child nodes and a nextSibling and previousSibling.

What is the difference between element and node in XML?

An Element is part of the formal definition of a well-formed XML document, whereas a node is defined as part of the Document Object Model for processing XML documents.

Is text node an element?

HTML Elements are Nodes Texts are nodes. Some elements contain other nodes.

What's an element node?

The Element Node is a temporary harvestable structure that is added to the game in the Extinction DLC. It functions in a similar manner to Orbital Supply Drops in that it must be defended from Corrupted Creatures for a total of 5 waves while all the nodes are maturing.


2 Answers

This xml <people><student><name></name></student></people> has no text nodes.

This xml <people><student><name>John</name></student></people> has one text node John

This xml

<people>
    <student>
        <name>John</name>
    </student>
</people>  

has 5 text nodes, text node 1 is spaces and CRLF between <people> and <student> and so on

like image 85
Evgeniy Dorofeev Avatar answered Oct 16 '22 08:10

Evgeniy Dorofeev


All the XML elements present in a XML is an element node. The text present in the XML elements are text nodes.

like image 39
karthick Avatar answered Oct 16 '22 10:10

karthick