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

前端 未结 13 1391
清酒与你
清酒与你 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 01:14

    An element is a type of node as are attributes, text etc.

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

    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'.

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

    A node is the base class for both elements and attributes (and basically all other XML representations too).

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

    node & element are same. Every element is a node , but it's not that every node must be an element.

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

    Element is the only kind of node that can have child nodes and attributes.

    Document also has child nodes, BUT
    no attributes, no text, exactly one child element.

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

    A node can be a number of different kinds of things: some text, a comment, an element, an entity, etc. An element is a particular kind of node.

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