I'm working in Java with XML and I'm wondering; what's the difference between an element and a node?
相关问题
- Illegal to have multiple roots (start tag in epilo
- Newtonsoft DeserializeXNode expands internal array
- how to use special characters like '<'
- XML - XSLT - document() function inside count() fu
- convert logback.xml to log4j.properties
相关文章
- Creating XML Elements without namespace declaratio
- Get Attribute Value From Simple XML Using JQuery /
- Directly signing an Office Word document using XML
- When sending XML to JMS should I use TextMessage o
- Fragment Content Overlaps Toolbar and Bottom Navig
- Getting “Error: Missing Constraints in ConstraintL
- xslt localization
- Upgrading transaction.commit_manually() to Django
A Node is a part of the DOM tree, an Element is a particular type of Node
e.g.
<foo> This is Text </foo>
You have a foo Element, (which is also a Node, as Element inherits from Node) and a Text Node 'This is Text', that is a child of the foo Element/Node
The Node object is the primary data type for the entire DOM.
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.
An XML element is everything from (including) the element's start tag to (including) the element's end tag.
A node is the base class for both elements and attributes (and basically all other XML representations too).
Different W3C specifications define different sets of "Node" types.
Thus, the DOM spec defines the following types of nodes:
Document
--Element
(maximum of one),ProcessingInstruction
,Comment
,DocumentType
DocumentFragment
--Element
,ProcessingInstruction
,Comment
,Text
,CDATASection
,EntityReference
DocumentType
-- no childrenEntityReference
--Element
,ProcessingInstruction
,Comment
,Text
,CDATASection
,EntityReference
Element
--Element
,Text
,Comment
,ProcessingInstruction
,CDATASection
,EntityReference
Attr
--Text
,EntityReference
ProcessingInstruction
-- no childrenComment
-- no childrenText
-- no childrenCDATASection
-- no childrenEntity
--Element
,ProcessingInstruction
,Comment
,Text
,CDATASection
,EntityReference
Notation
-- no childrenThe XML Infoset (used by XPath) has a smaller set of nodes:
XPath has the following Node types:
The answer to your question "What is the difference between an element and a node" is:
An element is a type of node. Many other types of nodes exist and serve different purposes.
An element is a type of node as are attributes, text etc.
An xml document is made of nested elements. An element begins at its opening tag and ends at its closing tag. You're probably seen
<body>
and</body>
in html. Everything between the opening and closing tags is the element's content. If an element is defined by a self-closing tag (eg.<br/>
) then its content is empty.Opening tags can also specify attributes, eg.
<p class="rant">
. In this example the attribute name is 'class' and its value 'rant'.The XML language has no such thing as a 'node'. Read the spec, the word doesn't occur.
Some people use the word 'node' informally to mean element, which is confusing because some parsers also give the word a technical meaning (identifying 'text nodes' and 'element nodes'). The exact meaning depends on the parser, so the word is ill-defined unless you state what parser you are using. If you mean element, say 'element'.