Skip to content

Commit

Permalink
Added accessing attributes through subscript
Browse files Browse the repository at this point in the history
  • Loading branch information
OrkhanAlikhanov committed May 26, 2018
1 parent 78e2da1 commit 5376bf0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Sources/XmlElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,29 @@ import Foundation
open class XmlElement {
open var name: String
open var attributes: [String:String] = [:]
open var text: String = "" //I guess this is ok.
open var text: String
open var children: [XmlElement] = []
open var parent: XmlElement?

public init(name: String, xmlns: String? = nil) {
public init(name: String, xmlns: String? = nil, text: String = "") {
self.name = name
self.text = text
attributes["xmlns"] = xmlns
}

open var xml: String {
//TODO: generate compact xml
return "<\(name)\(attributes.map({" \($0)=\"\($1)\" "}).joined())>\(text)\(children.map({ $0.description }).joined())</\(name)>"
}

open subscript(key: String) -> String? {
get {
return attributes[key]
}
set {
attributes[key] = newValue
}
}
}

extension XmlElement: CustomStringConvertible {
Expand Down
2 changes: 1 addition & 1 deletion Xml.swift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Xml.swift'
s.version = '1.0.0'
s.version = '1.1.0'
s.summary = 'An XMLParser wrapper for swift.'
s.homepage = 'https://github.com/BiAtoms/Xml.swift'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down

0 comments on commit 5376bf0

Please sign in to comment.