Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make XMLElement children property public #83

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/SWXMLHash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public class XMLElement: XMLContent {
.reduce("", combine: { $0 + $1!.text })
}

var children = [XMLContent]()
public var children = [XMLContent]()
var count: Int = 0
var index: Int

Expand Down
20 changes: 20 additions & 0 deletions Tests/SWXMLHashSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ class SWXMLHashTests: QuickSpec {
expect(xml!["root"]["header"].element?.text).to(equal("header mixed contentmore mixed content"))
}

it("should be able to iterate over mixed content") {
let mixedContentXml = "<html><body><p>mixed content <i>iteration</i> support</body></html>"
let parsed = SWXMLHash.parse(mixedContentXml)
let result = parsed["html"]["body"]["p"].element!.children.reduce("") { acc, child in
switch child {
case let elm as XMLElement:
guard let text = elm.text else { return acc }
return acc + text
case let elm as TextElement:
return acc + elm.text
default:
XCTAssert(false, "Unknown element type")
return acc
}
}

expect(result).to(equal("mixed content iteration support"))

}

it("should handle interleaving XML elements") {
let interleavedXml = "<html><body><p>one</p><div>two</div><p>three</p><div>four</div></body></html>"
let parsed = SWXMLHash.parse(interleavedXml)
Expand Down