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 a Document is .document.

    Declaration

    Swift

    public static let nodeType: NodeType = .document
  • The nodeName of a Document is #document.

    Declaration

    Swift

    public final let nodeName: String = "#document"
  • The nodeValue of a Document is nil.

    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 a Document is nil.

    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()
  • A document node first calls beginVisit(self) on the visitor. It then calls accept on each of the nodes in the children array, passing the visitor object. Finally, it calls endVisit(self) on the visitor.

    Declaration

    Swift

    public func accept(_ visitor: Visitor)
  • 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

    Swift

    public final func elements(where predicate: @escaping (Element) -> Bool) -> [Element]

    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.