Instance Method

nodesForXPath:error:

Returns the nodes resulting from executing an XPath query upon the receiver.

Declaration

- (NSArray<__kindof NSXMLNode *> *)nodesForXPath:(NSString *)xpath error:(NSError * _Nullable *)error;

Parameters

xpath

A string that expresses an XPath query.

error

If query errors occur, indirectly returns an NSError object describing the errors.

Return Value

An array of NSXMLNode objects that match the query, or an empty array if there are no matches.

Discussion

The receiver acts as the context item for the query (“.”). If you have explicitly added adjacent text nodes as children of an element, you should invoke the NSXMLElement method normalizeAdjacentTextNodesPreservingCDATA: (with an argument of NO) on the element before applying any XPath queries to it; this method coalesces these text nodes. The same precaution applies if you have processed a document preserving CDATA sections and these sections are adjacent to text nodes.

See Also

Executing Queries

- objectsForXQuery:error:

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

- objectsForXQuery:constants:error:

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

XPath

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