 |
XML General XML discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

May 6th, 2010, 04:36 PM
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Confusion with terminology...
Can anyone tell me what the difference is between an XML Node and an XML Element? I use these terms interchangeably, so for the sake of sounding component and not sounding foolish I would like someone who knows to chime in.
|

May 6th, 2010, 04:55 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Elements are only one of the many types of node. Attributes, comments, processing instructions are some of the others. You can see a list here: http://www.w3schools.com/dom/dom_nodetype.asp
If you think in terms of object oriented programming then a node is like an abstract base class with the concrete types such as element and attribute inheriting from it.
|
The Following User Says Thank You to joefawcett For This Useful Post:
|
|

May 6th, 2010, 04:59 PM
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
So you're saying elements, attributes, etc are all types of elements?
I was under the following impression:
<test number1="000" number2="111"/>
<test></test> is the node. While test, the number1 and number2 attributes all together are referred to as an element.
|

May 6th, 2010, 05:06 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
No, elements, attributes etc are all types of nodes.
If you think of it like this:
Node
\--- Element
\--- Attribute
\--- Processing instruction
\--- Text
In your above example there is a node, of type 'element' whose name is 'test'.
That node has some children on its attribute axis. There are two nodes on the attribute axis, of type 'attribute'. The first has a local name of 'number1' and a value of '000' etc.
<test>some text</test>
The above element node (again with a name of 'test') has one child node, of type 'text' with a value of 'some text'.
Hope that helps.
|
The Following User Says Thank You to samjudson For This Useful Post:
|
|

May 6th, 2010, 05:10 PM
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Whoops, yeah, I mis-worded my response. I meant, So you're saying elements, attributes, etc are all types of nodes?
Thanks guys!
|

May 7th, 2010, 06:36 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>So you're saying elements, attributes, etc are all types of nodes?
That's correct. Though in the XPath family of specs we tend to say they are different kinds of node, to avoid any confusion with "type" in the sense that, for example, an attribute or element can be of (= have content of) type integer or date.
Using "Node" to mean "Element" is one of the common terminological slips found among people who use XML but haven't really studied it. Another one that's perhaps even more common, and worse, is using "Tag" to mean "Element". (It's wrong because an element has two tags, a start tag and an end tag.)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
 |