cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the absolute path of a XML node via OpenXML/XPath?

VolkerBarth
Contributor
0 Kudos
2,485

I'm trying to analyse a quite complex (and unfortunately mainly undocumented) XML document via SA's OpenXML() operator.

While it's easy to return all nodes with a particular value, I need to get to know their according absolute pathes.

Is there a way to do so, except recursively accessing the parent node? (With DOM, I would use the getNodePath() function.)

The XPath 3 path() function would help here but seems to be unsupported with v16:

select *
from openxml(using value varXml, '//*')
 with
 (ID int  '@mp:id',
  ElementName long varchar '@mp:localname',
  ParentElementName long varchar '../@mp:localname',
  -- I'd prefer not to need to extend that to further levels...
  GrandParentElementName long varchar '../../@mp:localname',
  ElementText long varchar 'text()',
  -- ElementPath long varchar 'path()', -- not supported
  ElementXmlText long varchar '@mp:xmltext') DT
where ElementText = <desired value="">;

Accepted Solutions (0)

Answers (0)