Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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
 
Old May 6th, 2010, 04:36 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default 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.
 
Old May 6th, 2010, 04:55 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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.
__________________
Joe
http://joe.fawcett.name/
The Following User Says Thank You to joefawcett For This Useful Post:
vb89 (May 6th, 2010)
 
Old May 6th, 2010, 04:59 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default

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.
 
Old May 6th, 2010, 05:06 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
vb89 (May 6th, 2010)
 
Old May 6th, 2010, 05:10 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Whoops, yeah, I mis-worded my response. I meant, So you're saying elements, attributes, etc are all types of nodes?

Thanks guys!
 
Old May 7th, 2010, 06:36 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Some confusion in these code hpatel_it ASP.NET 1.0 and 1.1 Basics 0 August 30th, 2006 08:19 AM
Terminology? jacob C# 3 July 28th, 2005 03:33 PM
.net Confusion reyboy General .NET 1 December 29th, 2004 08:35 AM
Some confusion as to which SQL to use mark.uk SQL Server 2000 6 August 12th, 2004 10:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.