<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLNode/xPath",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLNode(py)XPath"
  },
  "title" : "xPath"
}
-->

# xPath

Returns the XPath expression identifying the receiver’s location in the document tree.

```
var xPath: String? { get }
```

## Discussion

For example, this method might return a string such as “foo/bar[2]/baz”. The result of this method can be used directly in the [`nodes(forXPath:)`](/documentation/Foundation/XMLNode/nodes(forXPath:)) and [`objects(forXQuery:constants:)`](/documentation/Foundation/XMLNode/objects(forXQuery:constants:)) methods.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)