liveBook · Manning

XPath

As explained in 100 SQL Server Mistakes and How to Avoid Them

XPath is a W3C language for navigating and selecting nodes in an XML document.

XPath is a W3C language for navigating XML nodes and selecting specific nodes. With SQL Server OPENXML(), an XPath pattern identifies the hierarchy level treated as rows. section 3.4.1

Use XPath carefully when shredding hierarchical XML:

  • Point the XPath expression at the lowest hierarchy level that should produce rows. section 3.4.1
  • Use the ../ operator in mappings to traverse from a lower-level node to its parent data. section 3.4.1
  • Prepare the XML with sp_xml_preparedocument before OPENXML(), then call sp_xml_removedocument to release the in-memory tree. section 3.4.1

Employee contracts

For XML containing Employee, Contract, and Skill nodes, select the lowest-level row hierarchy with an XPath pattern, then map employee and contract values by traversing upward with ../. section 3.4.1

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Defines navigation, row selection, and ../ traversal but stops short of broader XPath syntax.
Examples
Uses nested employee, contract, and skill XML with upward ../ mappings.
What it assumes
Assumes XML hierarchy awareness while defining node navigation and selection from the stated W3C language role.
What you can do after
Apply it via OPENXML() to select XML rows and retrieve values from higher hierarchy levels.
How it connects
Connects XML documents with OPENXML(), sp_xml_preparedocument, and XML node mappings.

Also explained in

Compare how 3 books explain XPath →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.