web analytics

Document Node vs Root Element in XPath

Options

codeling 1599 - 6654
@2016-01-17 18:52:42

In a well-formed XML document, there is  the only root element, i.e. the top level of the XML element hierarchy. The root element is in turn a child of the document root. The document root is the top level of the XML node hierarchy i.e. contains all other nodes (such as the comment node, processing instruction node etc.) in the XML document (including the root element).

In the example belows, thr root element is greetings, but the document root contains greetings node and a comment node.

<?xml version="1.0" ?>
<!-- comments -->
<greetings>
 <greeting language="english">Hello</greeting>
 <greeting language="english">World</greeting>
</greetings>

 

@2016-01-18 12:44:27

In XPath, "/" refers to the document node which contains all elements including the root element and any top-level comments and processing instructions. The document node is not a element and has no name.

"/*" refers to root element which is the only element child of the document node in a well-formed XML document, its name is name(/*).

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com