XMLNodeSet

public final class XMLNodeSet

Instances of this class represent an immutable collection of DOM nodes. An instance provides the interface similar to the Node’s one.

  • Concatenated HTML content of nodes in the collection. May be nil if no content is available.

    Declaration

    Swift

    public var html: String?
  • xml

    Concatenated XML content of nodes in the collection. May be nil if no content is available.

    Declaration

    Swift

    public var xml: String?
  • Concatenated inner HTML content of nodes in the collection.

    Declaration

    Swift

    public var innerHTML: String?
  • Concatenated text content of nodes in the collection. May be nil if no content is available.

    Declaration

    Swift

    public var text: String?
  • Creates an empty collection of nodes.

    Declaration

    Swift

    public init()
  • Creates a collection of nodes from the provided array of XMLElements

    Declaration

    Swift

    public init(nodes: [XMLElement])

    Parameters

    nodes

    Nodes to create a node set from.

  • The position of the first element in a nonempty collection.

    If the collection is empty, startIndex is equal to endIndex.

    Declaration

    Swift

    public var startIndex: Int
  • Accesses the element at the specified position.

    The following example accesses an element of an array through its subscript to print its value:

    var streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
    print(streets[1])
    // Prints "Bryant"
    

    You can subscript a collection with any valid index other than the collection’s end index. The end index refers to the position one past the last element of a collection, so it doesn’t correspond with an element.

    Parameter

    Parameter position: The position of the element to access. position must be a valid index of the collection that is not equal to the endIndex property.

    Declaration

    Swift

    public subscript(position: Int) -> XMLElement

    Parameters

    position

    The position of the element to access. position must be a valid index of the collection that is not equal to the endIndex property.

  • The collection’s past the end position—that is, the position one greater than the last valid subscript argument.

    When you need a range that includes the last element of a collection, use the half-open range operator (..<) with endIndex. The ..< operator creates a range that doesn’t include the upper bound, so it’s always safe to use with endIndex. For example:

    let numbers = [10, 20, 30, 40, 50]
    if let index = numbers.index(of: 30) {
        print(numbers[index ..< numbers.endIndex])
    }
    // Prints "[30, 40, 50]"
    

    If the collection is empty, endIndex is equal to startIndex.

    Declaration

    Swift

    public var endIndex: Int
  • Returns the position immediately after the given index.

    Parameter

    Parameter i: A valid index of the collection. i must be less than endIndex.

    Returns

    The index value immediately after i.

    Declaration

    Swift

    public func index(after i: Int) -> Int

    Parameters

    i

    A valid index of the collection. i must be less than endIndex.

    Return Value

    The index value immediately after i.

  • Returns a Boolean value indicating whether two values are equal.

    Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

    • Parameters:
      • lhs: A value to compare.
      • rhs: Another value to compare.

    Declaration

    Swift

    public static func ==(lhs: XMLNodeSet, rhs: XMLNodeSet) -> Bool

    Parameters

    lhs

    A value to compare.

    rhs

    Another value to compare.

  • A 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 to s uses the Point type’s description property.

    Declaration

    Swift

    public var description: String