Adam
Adam

Reputation: 10016

Using '.' (dot or period) in an XPath expression

Can someone tell me the difference between the following XPath expressions?

/IntuitResponse/QueryResponse/Bill/./Id
/IntuitResponse/QueryResponse/Bill/Id

I've tried using both to parse an XML document from the document root and I'm getting the same response.

Upvotes: 1

Views: 2661

Answers (1)

kjhughes
kjhughes

Reputation: 111541

Those two XPaths are equivalent.

The abbreviation for self::node() (.) is more useful within a predicate. For example,

/IntuitResponse/QueryResponse/Bill/Id[. = 'abc']

would select only those Id elements whose string value is 'abc'.

Also, . is useful to introduce a relative path. For example,

./Id

would select only those Id elements that are a child of the current context node.

Upvotes: 5

Related Questions