xpathGenerate method

String xpathGenerate({
  1. String? byId,
})

Generates a canonical XPath 3.1 path expression that selects this node.

The generated path conforms to the W3C XPath 3.1 fn:path specification. Paths starting from an XmlDocument root begin with /. Elements without an explicit namespace URI use Q{} notation, while elements with a namespace URI use Q{uri} notation followed by a 1-based positional index among matching sibling elements.

If byId specifies a fully qualified attribute name, the presence of that attribute causes the generation of a shorter lookup expression.

For example:

final document = XmlDocument.parse('<root><item>first</item><item>second</item></root>');
final secondItem = document.findAllElements('item').last;
print(secondItem.xpathGenerate()); // /Q{}root[1]/Q{}item[2]

Implementation

String xpathGenerate({String? byId}) => xpathNodePath(this, byId: byId);