Visitor
public protocol Visitor
The Visitor Design Pattern is used throughout the MiniDOM library to implement algorithms that involve traversing the DOM tree. It provides a convenient mechanism to separate an algorithm from the object structure on which it operates. It allows operations to be added to the DOM structure without modifying the structures themselves.
A Visitor object is provided to Node.accept(_:) to start the traversal. The
Node object calls the appropriate methods on the Visitor object before
calling Node.accept(_:) on its child nodes, performing the recursive
traversal.
The Visitor protocol defines methods that correspond to each of the Node
types in the DOM. Types implementing the Visitor protocol do not need to
deal with the actual traversal; its methods are called by the traversal
algorithm provided by the DOM classes.
For a simple example of a visitor, see the ElementSearch class in
Search.swift. For a more complex example of a visitor, see the
PrettyPrinter class in Formatter.swift.
-
beginVisit(_:)Default implementationCalled when the traversal algorithm encounters a
Documentobject before itschildrenare traversed.Visiting a
Documentobject is split into a begin and end method to allow implementing operations before and after thechildrenof theDocumentobject are visited.Default Implementation
Default implementation does nothing.
Default implementation does nothing.
Declaration
Swift
func beginVisit(_ document: Document) -
endVisit(_:)Default implementationCalled when the traversal algorithm encounters a
Documentobject after itschildrenare traversed.Visiting a
Documentobject is split into a begin and end method to allow implementing operations before and after thechildrenof theDocumentobject are visited.Default Implementation
Default implementation does nothing.
Default implementation does nothing.
Declaration
Swift
func endVisit(_ document: Document) -
Called when the traversal algorithm encounters an
Elementobject before itschildrenare traversed.Visiting an
Elementobject is split into a begin and end method to allow implementing operations before and after thechildrenof theElementobject are visited.Declaration
Swift
func beginVisit(_ element: Element) -
Called when the traversal algorithm encounters an
Elementobject after itschildrenare traversed.Visiting an
Elementobject is split into a begin and end method to allow implementing operations before and after thechildrenof theElementobject are visited.Declaration
Swift
func endVisit(_ element: Element) -
visit(_:)Default implementation -
Called when the traversal algorithm encounters a
ProcessingInstructionobject.Declaration
Swift
func visit(_ processingInstruction: ProcessingInstruction) -
Called when the traversal algorithm encounters an
CDATASectionobject.Declaration
Swift
func visit(_ cdataSection: CDATASection)
View on GitHub
Install in Dash
Visitor Protocol Reference