问题
I am working through a tutorial on the W3Schools website about XML. This is the page I'm on: http://www.w3schools.com/xsl/xquery_terms.asp
I'm a bit confused about the difference between an atomic node and a leaf node. Are they the same thing? I know that a leaf node is a node without any children, but it also seems that the atomic nodes in the given example don't have any children either.
The W3Schools site says "Atomic values are nodes with no children or parent." Surely it's impossible for a node not to have a parent, as all the nodes in an XML document have to come under the root node (the document root)?
Can anyone explain this to me as I'm confused.
Thanks.
回答1:
The example shows that "J K. Rowling" is atomic.
It has no parent, and no child. It's just a value or a node in itself.
(Imagine a text file with just that line)
But this: <author>J K. Rowling</author>
, has a parent and a child.
* Parent: author
* Child: J K. Rowling
Author may have no parent, but it is not atomic since it has a child.
J K. Rowling may have no child, but it is not atomic since it has a parent.
Meanwhile, a leaf node as no child, but it may or may not have a parent.
So overall, an atomic node is just a subset of a leaf node.
回答2:
I find that w3schools is often a useful resource for looking up details of information that I knew once but had forgotten, but it's a very poor resource for learning new concepts. This example is typical: "Atomic values are nodes with no children or parent.". Wrong, totally wrong. Atomic values are not nodes. In the XDM model used by XQuery, there are two kinds of item, nodes and atomic values. I suggest you use a different resource that isn't going to cause unnecessary confusion by giving wrong information.
回答3:
In the XQuery Data Model, an atomic value is not a node. It is a value labeled with an atomic type.
Hence, a node (even a leaf node) is never an atomic value, just like an atomic value is never a node. However, a node can be "atomized" to an atomic value, in which case its typed value is taken (if it has any).
来源:https://stackoverflow.com/questions/7711740/in-xml-is-an-atomic-node-the-same-thing-as-a-leaf-node