XML 中的元素和节点有什么区别?

发布于 2024-07-06 06:50:26 字数 47 浏览 5 评论 0原文

我正在使用 Java 和 XML 进行工作,我想知道; 元素和节点有什么区别?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

甚是思念 2024-07-13 06:50:26

Node 对象是整个 DOM 的主要数据类型。

节点可以是元素节点、属性节点、文本节点或“节点类型”章节中解释的任何其他节点类型。

XML 元素是从(包括)元素的开始标记到(包括)元素的结束标记的所有内容。

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.

转角预定愛 2024-07-13 06:50:26

不同的 W3C 规范定义了不同的“节点”类型集。

因此, DOM 规范 定义了以下类型的节点:

  • 文档 -- 元素(最多
    一),处理指令
    注释文档类型
  • 文档片段
    -- 元素处理指令
    注释文本CDATASectionEntityReference
  • 文档类型 --
    没有孩子
  • 实体引用
    -- 元素处理指令
    注释文本CDATASectionEntityReference
  • 元素 -- 元素文本注释处理指令
    CDATASectionEntityReference
  • Attr -- 文本EntityReference
  • 处理指令
    - 没有孩子
  • 评论 -- 没有
    孩子们
  • 文本 -- 否
    孩子们
  • CDATASection --
    没有孩子
  • 实体 -- 元素ProcessingInstruction
    注释文本CDATASectionEntityReference
  • 符号 -- 否
    孩子们

XML 信息集(由 XPath 使用)具有较小的节点集:

  • 文档信息项
  • 元素信息项
  • 属性信息项
  • 处理指令信息项
  • 未展开的实体参考信息项
  • 字符信息项
  • 注释信息项
  • 文档类型声明信息项
  • 未解析的实体信息项
  • 符号信息项
  • 命名空间信息项
  • XPath 具有以下节点类型:

    • 根节点
    • 元素节点
    • 文本节点
    • 属性节点
    • 命名空间节点
    • 处理指令节点
    • 注释节点

    问题的答案元素和节点有什么区别”是:

    元素是一种节点类型。 存在许多其他类型的节点并服务于不同的目的。

    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.

    遗弃M 2024-07-13 06:50:26

    节点是 DOM 树的一部分,元素是特定类型的节点,

    例如
    <代码>; 这是文本

    您有一个 foo 元素(它也是一个节点,因为元素继承自 Node)和一个文本节点“这是文本”,它是 foo 元素的子节点/节点

    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

    远昼 2024-07-13 06:50:26

    节点可以是多种不同类型的事物:一些文本、注释、元素、实体等。元素是一种特定类型的节点。

    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.

    来日方长 2024-07-13 06:50:26

    正如各种 XML 规范中所述, 元素 是由开始标记、结束标记以及中间的内容组成的,或者是由空元素标记(没有内容或结束标记)组成的。 换句话说,这些都是元素:

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

    虽然您听到的“节点”的含义大致相同,但根据 XML 规范它没有精确的定义。 它通常用于指代诸如 DOM 之类的事物的节点,这些节点可能与 XML 密切相关或使用 XML 进行表示。

    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.

    橘香 2024-07-13 06:50:26

    xml 文档由嵌套元素组成。 元素从其开始标记开始,并以其结束标记结束。 您可能在 html 中看到过 。 开始标签和结束标签之间的所有内容都是元素的内容。 如果元素是由自闭合标签定义的(例如
    ),则其内容为空。

    开始标签还可以指定属性,例如。

    。 在此示例中,属性名称是“class”,其是“rant”。

    XML 语言没有“节点”这样的东西阅读规范,这个词没有出现。

    有些人非正式地使用“节点”一词来表示元素,这很令人困惑,因为一些解析器还赋予该词技术含义(标识“文本节点”和“元素节点”)。 确切的含义取决于解析器,因此该词的定义不明确,除非您说明您正在使用的解析器。 如果您指的是元素,请说“元素”

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

    高冷爸爸 2024-07-13 06:50:26

    节点是元素和属性(基本上也是所有其他 XML 表示形式)的基类。

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

    颜漓半夏 2024-07-13 06:50:26

    元素是唯一一种可以具有子节点和属性的节点

    文档也有子节点,但是
    没有属性,没有文本,只有一个子元素。

    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.

    顾冷 2024-07-13 06:50:26

    节点定义为:

    文档中有效、完整结构的最小单位。

    或作为:

    树视图中的对象,用作保存相关对象的容器。

    现在它们有许多不同类型的节点,如元素节点、属性节点等。

    (于 2024 年 2 月 24 日编辑以删除指向完全不相关的 IBM 网页的链接)

    A node is defined as:

    the smallest unit of a valid, complete structure in a document.

    or as:

    An object in the tree view that serves as a container to hold related objects.

    Now their are many different kinds of nodes as an elements node, an attribute node etc.

    (Edited 2024-02-24 to remove a link, which pointed to a completely irrelevant IBM web page)

    风蛊 2024-07-13 06:50:26

    现在我知道,该元素是节点之一,

    这里的所有节点类型“http://www.w3schools.com/dom/dom_nodetype.asp" w3schools.com/dom/dom_nodetype.asp"

    元素位于开始标签和结束标签之间,

    因此文本节点是一个节点,但不是一个元素。

    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.

    甜尕妞 2024-07-13 06:50:26

    元素是一种节点类型,属性、文本等也是如此。

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

    九命猫 2024-07-13 06:50:26

    XML 元素是一个 XML 节点,但具有属性等附加元素。

    <a>Lorem Ipsum</a>  //This is a node
    
    <a id="sample">Lorem Ipsum</a>  //This is an element
    

    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
    
    迷鸟归林 2024-07-13 06:50:26

    节点和 元素相同。 每个元素都是一个节点,但并不是每个节点都必须是一个元素。

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

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文