Instance Method

nodes(forXPath:)

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

Declaration

func nodes(forXPath xpath: String) throws -> [XMLNode]

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 false) 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

func objects(forXQuery: String) -> [Any]

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

func objects(forXQuery: String, constants: [String : Any]?) -> [Any]

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

var xPath: String?

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