Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tadija/AEXML
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: AssistoLab/AEXML
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 4 commits
  • 1 file changed
  • 2 contributors

Commits on Mar 23, 2016

  1. Copy the full SHA
    e88f3b2 View commit details

Commits on Mar 29, 2016

  1. Copy the full SHA
    8cdb5e2 View commit details
  2. Copy the full SHA
    8e0ade7 View commit details
  3. Copy the full SHA
    d594017 View commit details
Showing with 36 additions and 17 deletions.
  1. +36 −17 Source/AEXML.swift
53 changes: 36 additions & 17 deletions Source/AEXML.swift
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ public class AEXMLElement: NSObject {
return self
} else {
let filtered = children.filter { $0.name == key }
let errorElement = AEXMLElement(AEXMLElement.errorElementName, value: "element <\(key)> not found")
let errorElement = AEXMLElement(AEXMLElement.errorElementName, value: nil)
return filtered.count > 0 ? filtered.first! : errorElement
}
}
@@ -231,13 +231,21 @@ public class AEXMLElement: NSObject {
}
return indent
}


public static var prettyPrint = true

private var prettyPrint: Bool {
return AEXMLElement.prettyPrint
}

/// Complete hierarchy of `self` and `children` in **XML** escaped and formatted String
public var xmlString: String {
var xml = String()

// open element
xml += indentation(parentsCount - 1)
if prettyPrint {
xml += indentation(parentsCount - 1)
}
xml += "<\(name)"

if attributes.count > 0 {
@@ -253,13 +261,21 @@ public class AEXMLElement: NSObject {
} else {
if children.count > 0 {
// add children
xml += ">\n"
xml += ">"
if prettyPrint {
xml += "\n"
}
for child in children {
xml += "\(child.xmlString)\n"
xml += "\(child.xmlString)"
if prettyPrint {
xml += "\n"
}
}
// add indentation
xml += indentation(parentsCount - 1)
xml += "</\(name)>"
if prettyPrint {
// add indentation
xml += indentation(parentsCount - 1)
}
xml += "</\(name)>"
} else {
// insert string value and close element
xml += ">\(escapedStringValue)</\(name)>"
@@ -388,14 +404,17 @@ public class AEXMLDocument: AEXMLElement {
// MARK: Override

/// Override of `xmlString` property of `AEXMLElement` - it just inserts XML Document header at the beginning.
public override var xmlString: String {
var xml = "<?xml version=\"\(version)\" encoding=\"\(encoding)\" standalone=\"\(standalone)\"?>\n"
for child in children {
xml += child.xmlString
}
return xml
}

public override var xmlString: String {
var xml = "<?xml version=\"\(version)\" encoding=\"\(encoding)\" standalone=\"\(standalone)\"?>"
if prettyPrint {
xml += "\n"
}
for child in children {
xml += child.xmlString
}
return xml
}

}

// MARK: -
@@ -460,4 +479,4 @@ private class AEXMLParser: NSObject, NSXMLParserDelegate {
self.parseError = parseError
}

}
}