---
title: "objects(forXQuery:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/xmlnode/objects(forxquery:)"
---

# objects(forXQuery:)

Returns the objects resulting from executing an XQuery query upon the receiver.

## Declaration

```swift
func objects(forXQuery xquery: String) throws -> [Any]
```

## Parameters

- `xquery`: A string that expresses an XQuery query.

## Discussion

Discussion The receiver acts as the context item for the query (”.”).  If the receiver has been changed after parsing to have multiple adjacent text nodes, you should invoke the NSXMLElement method normalizeAdjacentTextNodesPreservingCDATA(_:) (with an argument of false) to coalesce the text nodes before querying .This convenience method invokes objects(forXQuery:constants:) with nil for the constants dictionary. note: In Swift, this method returns a nonoptional result and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Executing Queries

- [nodes(forXPath:)](foundation/xmlnode/nodes(forxpath:).md)
- [objects(forXQuery:constants:)](foundation/xmlnode/objects(forxquery:constants:).md)
- [xPath](foundation/xmlnode/xpath.md)
