AEXMLElement

public class AEXMLElement: NSObject

This is base class for holding XML structure.

You can access its structure by using subscript like this: element["foo"]["bar"] would return <bar></bar> element from <element><foo><bar></bar></foo></element> XML as an AEXMLElement object.

  • Every AEXMLElement should have its parent element instead of AEXMLDocument which parent is nil.

    Declaration

    Swift

    public private(set) weak var parent: AEXMLElement?
  • Child XML elements.

    Declaration

    Swift

    public private(set) var children: [AEXMLElement] = [AEXMLElement]()
  • XML Element name (defaults to empty string).

    Declaration

    Swift

    public var name: String
  • XML Element value.

    Declaration

    Swift

    public var value: String?
  • XML Element attributes (defaults to empty dictionary).

    Declaration

    Swift

    public var attributes: [String : String]
  • String representation of value property (if value is nil this is empty String).

    Declaration

    Swift

    public var stringValue: String { return value ?? String() }
  • String representation of value property with special characters escaped (if value is nil this is empty String).

    Declaration

    Swift

    public var escapedStringValue: String
  • Boolean representation of value property (if value is true or 1 this is True, otherwise False).

    Declaration

    Swift

    public var boolValue: Bool { return stringValue.lowercaseString == "true" || Int(stringValue) == 1 ? true : false }
  • Integer representation of value property (this is 0 if value can’t be represented as Integer).

    Declaration

    Swift

    public var intValue: Int { return Int(stringValue) ?? 0 }
  • Double representation of value property (this is 0.00 if value can’t be represented as Double).

    Declaration

    Swift

    public var doubleValue: Double { return (stringValue as NSString).doubleValue }
  • Designated initializer - all parameters are optional.

    :param: name XML element name. :param: value XML element value :param: attributes XML element attributes

    :returns: An initialized AEXMLElement object.

    Declaration

    Swift

    public init(_ name: String? = nil, value: String? = nil, attributes: [String : String]? = nil)
  • This element name is used when unable to find element.

    Declaration

    Swift

    public static let errorElementName = "AEXMLError"
  • all

    Returns all of the elements with equal name as self (nil if not exists).

    Declaration

    Swift

    public var all: [AEXMLElement]? { return parent?.children.filter { $0.name == self.name } }
  • Returns the first element with equal name as self (nil if not exists).

    Declaration

    Swift

    public var first: AEXMLElement? { return all?.first }
  • Returns the last element with equal name as self (nil if not exists).

    Declaration

    Swift

    public var last: AEXMLElement? { return all?.last }
  • Returns number of all elements with equal name as self.

    Declaration

    Swift

    public var count: Int { return all?.count ?? 0 }
  • Returns all elements with given value.

    :param: value XML element value.

    :returns: Optional Array of found XML elements.

    Declaration

    Swift

    public func allWithValue(value: String) -> [AEXMLElement]?
  • Returns all elements with given attributes.

    :param: attributes Dictionary of Keys and Values of attributes.

    :returns: Optional Array of found XML elements.

    Declaration

    Swift

    public func allWithAttributes(attributes: [String : String]) -> [AEXMLElement]?
  • Adds child XML element to self.

    :param: child Child XML element to add.

    :returns: Child XML element with self as parent.

    Declaration

    Swift

    public func addChild(child: AEXMLElement) -> AEXMLElement
  • Adds child XML element to self.

    :param: name Child XML element name. :param: value Child XML element value. :param: attributes Child XML element attributes.

    :returns: Child XML element with self as parent.

    Declaration

    Swift

    public func addChild(name name: String, value: String? = nil, attributes: [String : String]? = nil) -> AEXMLElement
  • Removes self from parent XML element.

    Declaration

    Swift

    public func removeFromParent()
  • Complete hierarchy of self and children in XML escaped and formatted String

    Declaration

    Swift

    public var xmlString: String