|
|
|
SCWD home | SCJP home | XML books
XPath
-
XPath allows selected or filtered information from within the source XML data or document to be exchanged or displayed
-
XPath is designed to enable addressing of or navigation to chosen parts of an XML document
-
XPath is used to navigate a hierarchical structure
-
Context node: starting point
Axis - specific direction that is selected
Location steps - steps taken to reach the destination
- 7 nodes and 13 axes
- A location path consists of one or more location steps
- Node test: specifies the type of node selected and its expanded name
- Location step has 3 parts: axis, node test, zero or more predicates
- XPath has both abbreviated and unabbreviated syntax
- Unabbreviated syntax - axis::nodetest [predicate]
- The representation of the abstract structure of the XML document is called a data model
- 7 nodes are:
- Root node
- Element node
- Attribute node
- Text node
- Comment node
- Namespace node
- ProcessingInstruction node
- An element node is the parent of an attribute node but an attribute node is not the child of its parent element node.
- There is a way to determine the string value for a node:
- Root node: the string value is the concatenation of the string value of the text node descendants of the root node in document order.
- Element node: the string value is the concatenation of the string value of the text node children of the element node in document order
- A comment node does not have any expanded name
- A location path is a special form of an XPath expression that returns only a nodeset.
- Context in XPath has 5 parts:
- Context node
- A pair of non-zero positive integers (context position, context size)
- A set of variable bindings
- A function library
- The set of namespace declarations
- 13 axes are:
- Child
- Parent
- Ancestor
- Descendant
- Ancestor-or-self
- Descendant-or-self
- Following-sibling
- Preceding-sibling
- Following
- Preceding
- Attribute
- Namespace
- Self
- Important points on axes:
- Child node - it never returns an attribute or a namespace node
- Parent - if the context node is the root node, parent is null
- Descendant - all children and childrens children and so on are returned except attribute or namespace nodes
- Following-sibling - If the context node is attribute or namespace node, following-sibling is empty
- Preceding-sibling - If the context node is attribute or namespace node, preceding-sibling is empty
- Following - all nodes that are after the context node are returned except any descendants and excluding attribute or namespace nodes
- Following - all nodes that are before the context node are returned except any ancestors and excluding attribute or namespace nodes
- Attribute - if the context node is not element, null is returned
- Namespace - if the context node is not element, null is returned
- Self - contains the context node
- XPath expression returns any of these: Nodeset, Boolean, String or Number
- XPath expression returns any of these: Nodeset, Boolean, String or Number
- Nodeset functions:
Count(), Id(), Name(), Local-name(), Last(), Namespace-uri(), Position()
- Boolean functions:
True(), False(), Not(), Lang(), Boolean()
- Number functions:
Ceiling(), Floor(), Round(), Number(), Sum()
- String functions:
Concat(), Contains(), Normalize-space(), String(), Substring(), String-length(), Starts-with(), Substring-before(), Substring-after(), Translate()
- Absolute location paths are special case of relative location paths where the context node is the root node of the XML document.
SCWD home | SCJP home | XML books
|