Document
public final class Document: ParentNode
The Document
class represents the entire document. Conceptually, it is the
root of the document tree, and provides the primary access to the document’s
data.
-
The
nodeType
of aDocument
is.document
.Declaration
Swift
public static let nodeType: NodeType = .document
-
The
nodeName
of aDocument
is#document
.Declaration
Swift
public final let nodeName: String = "#document"
-
The
nodeValue
of aDocument
isnil
.Declaration
Swift
public final let nodeValue: String? = nil
-
The children of the document will contain the document element and any processing instructions or comments that are siblings of the documnent element.
Declaration
Swift
public final var children: [Node] = []
-
The
attributes
dictionary of aDocument
isnil
.Declaration
Swift
public final let attributes: [String : String]? = nil
-
This is a convenience attribute that allows direct access to the child node that is the root element of the document.
Declaration
Swift
public final var documentElement: Element?
-
Creates a new
Document
node.Declaration
Swift
public init()
-
Traverses the document tree, collecting
Element
nodes with the specified tag name from anywhere in the document.Declaration
Swift
public final func elements(withTagName name: String) -> [Element]
Parameters
name
Collect elements with this tag name.
Return Value
An array of elements with the specified tag name.
-
Traverses the document tree, collecting
Element
nodes that satisfy the given predicate from anywhere in the document.Declaration
Parameters
predicate
A closure that takes an element as its argument and returns a Boolean value indicating whether the element should be included in the returned array.
Return Value
An array of the elements that
predicate
allowed.