What's the difference between an element and a node in XML?

前端 未结 13 1390
清酒与你
清酒与你 2020-11-28 00:57

I\'m working in Java with XML and I\'m wondering; what\'s the difference between an element and a node?

相关标签:
13条回答
  • 2020-11-28 00:59

    As described in the various XML specifications, an element is that which consists of a start tag, and end tag, and the content in between, or alternately an empty element tag (which has no content or end tag). In other words, these are all elements:

    <foo> stuff </foo>
    <foo bar="baz"></foo>
    <foo baz="qux" />
    

    Though you hear "node" used with roughly the same meaning, it has no precise definition per XML specs. It's usually used to refer to nodes of things like DOMs, which may be closely related to XML or use XML for their representation.

    0 讨论(0)
  • 2020-11-28 00:59

    Now i know ,the element is one of node

    All node types in here"http://www.w3schools.com/dom/dom_nodetype.asp"

    Element is between the start tag and end in the end tag

    So text node is a node , but not a element.

    0 讨论(0)
  • 2020-11-28 01:01

    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

    0 讨论(0)
  • 2020-11-28 01:01

    XML Element is a XML Node but with additional elements like attributes.

    <a>Lorem Ipsum</a>  //This is a node
    
    <a id="sample">Lorem Ipsum</a>  //This is an element
    
    0 讨论(0)
  • 2020-11-28 01:10

    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.

    0 讨论(0)
  • 2020-11-28 01:12

    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 children
    • EntityReference -- Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
    • Element -- Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
    • Attr -- Text, EntityReference
    • ProcessingInstruction -- no children
    • Comment -- no children
    • Text -- no children
    • CDATASection -- no children
    • Entity -- Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
    • Notation -- no children

    The XML Infoset (used by XPath) has a smaller set of nodes:

  • The Document Information Item
  • Element Information Items
  • Attribute Information Items
  • Processing Instruction Information Items
  • Unexpanded Entity Reference Information Items
  • Character Information Items
  • Comment Information Items
  • The Document Type Declaration Information Item
  • Unparsed Entity Information Items
  • Notation Information Items
  • Namespace Information Items
  • XPath has the following Node types:

    • root nodes
    • element nodes
    • text nodes
    • attribute nodes
    • namespace nodes
    • processing instruction nodes
    • comment nodes

    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.

0 讨论(0)
提交回复
热议问题