Node
public protocol Node: Searchable, CustomStringConvertible
Instances of conforming types represent a document object model node that can be searched by an XPath or CSS selector and also provide the node’s underlying data in a number of ways.
In the HTML/XML DOM (Document Object Model), everything is a node:
The document itself is a document node;
All HTML/XML elements are element nodes;
All HTML/XML attributes are attribute nodes;
Text inside HTML elements are text nodes;
Comments are comment nodes.
-
Text content of the node. May be
nil
if no content is available.Declaration
Swift
var text: String?
-
HTML content of the node. May be
nil
if no content is available.Declaration
Swift
var html: String?
-
XML content of the node. May be
nil
if no content is available.Declaration
Swift
var xml: String?
-
HTML content of the node without outermost tags. Only available if the
html
property is notnil
.Declaration
Swift
var innerHTML: String?
-
Value of the attribute
class
of the node. This property isnil
if the node does not have aclass
attributeDeclaration
Swift
var className: String?
-
Name of the corresponding tag for this node.
Note
Setting this property tonil
does not make any change.Declaration
Swift
var tagName: String?
-
Content of the node. May be
nil
if no content is available.Declaration
Swift
var content: String?
-
description
Extension methodA textual representation of this instance.
Instead of accessing this property directly, convert an instance of any type to a string by using the
String(describing:)
initializer. For example:struct Point: CustomStringConvertible { let x: Int, y: Int var description: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(describing: p) print(s) // Prints "(21, 30)"
The conversion of
p
to a string in the assignment tos
uses thePoint
type’sdescription
property.Declaration
Swift
public var description: String