Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference root element/root node

 
Nitin Gogia
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone clarify the difference between root element and root node.
Root Element is the root element of document like <HTML> in case of an HTML document. Then what is root node ?
 
Karthik Jayaraman
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In XPath context,
root node is the "/" document root node for which all the other element notes are children.
the document element would be the only (immediate) child of the root node.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by karthik jayaraman:
In XPath context,
root node is the "/" document root node for which all the other element notes are children.
the document element would be the only (immediate) child of the root node.

No, the immediate children of document node can be comments and processing-intstructions too.
 
Hung Tang
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Root Element is the root element of document like <HTML> in case of an HTML document. Then what is root node ?

At least in DOM, there's not much difference between a node and an element. An Element IS-A Node that can perform more specific tasks that is suited for an element along with other tasks that Node can do. It's an inheritence thing An Attribute is a Node too, as well as ProcessingInstruction node, Comment Node, etc.
In the context of "trees" and that's what DOM really is, a node is a term often used to denote a particular item Object with relationships to other Objects in the tree (i.e. node has a parent, child siblings, ancestors, descendents, etc.)
So what I'm trying to say, root element and root node is the same thing, just depends on the context I suppose.
PS. root note and document nodes are two different things
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hung Tang
I'm sorry to say your explanation about Node and Element is incorrect. It is explained very clear on above two answers. There is no need to repeat. One is "/", One is "/*". In DOM. Document is a Node, Element is a Node, but not vice versa.
Karthik Jayaraman's answer is all correct, except he missed a little. That was why I did correct him a little.
Thanks!
Roseanne
[ May 30, 2003: Message edited by: Roseanne Zhang ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic