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
AEXMLElementshould have its parent element instead ofAEXMLDocumentwhich parent isnil.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
valueproperty (ifvalueisnilthis is empty String).Declaration
Swift
public var stringValue: String { return value ?? String() } -
String representation of
valueproperty with special characters escaped (ifvalueisnilthis is empty String).Declaration
Swift
public var escapedStringValue: String -
Boolean representation of
valueproperty (ifvalueistrue
or 1 this isTrue, otherwiseFalse).Declaration
Swift
public var boolValue: Bool { return stringValue.lowercaseString == "true" || Int(stringValue) == 1 ? true : false } -
Integer representation of
valueproperty (this is 0 ifvaluecan’t be represented as Integer).Declaration
Swift
public var intValue: Int { return Int(stringValue) ?? 0 } -
Double representation of
valueproperty (this is 0.00 ifvaluecan’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
AEXMLElementobject.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" -
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
selfasparent.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
selfasparent.Declaration
Swift
public func addChild(name name: String, value: String? = nil, attributes: [String : String]? = nil) -> AEXMLElement -
Removes
selffromparentXML element.Declaration
Swift
public func removeFromParent() -
Complete hierarchy of
selfandchildrenin XML escaped and formatted StringDeclaration
Swift
public var xmlString: String
View on GitHub
AEXMLElement Class Reference