x

XML – XPath

PREV     NEXT

XML XPath:


XPath allows selected or filtered information from within the source XML data or document to be exchanged or displayed


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

PREV     NEXT



Like it? Please Spread the word!

Post Your Thoughts