Skip to content

Commit

Permalink
Merge pull request #278 from drmohundro/feat/add-parent-to-xmlelement
Browse files Browse the repository at this point in the history
feat: add parent to XMLElement
  • Loading branch information
drmohundro authored Sep 27, 2024
2 parents 615f044 + 11f89c3 commit 6ae7b83
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v8.1.0 (September 27, 2024)

- Added the `parent` property to `XMLElement` (via [#278](https://github.com/drmohundro/SWXMLHash/pull/278) which closes [#277](https://github.com/drmohundro/SWXMLHash/issues/277))

## v8.0.0 (September 17, 2024)

- Added Swift 6.0 support (via [#283](https://github.com/drmohundro/SWXMLHash/pull/283))
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM swiftlang/swift:nightly-6.0-focal
FROM swift:6.0

ENV APP_HOME ./app
RUN mkdir $APP_HOME
Expand Down
3 changes: 3 additions & 0 deletions Source/XMLElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class XMLElement: XMLContent {
/// The name of the element
public let name: String

public private(set) var parent: XMLElement?

/// Whether the element is case insensitive or not
public var caseInsensitive: Bool {
options.caseInsensitive
Expand Down Expand Up @@ -116,6 +118,7 @@ public class XMLElement: XMLContent {

func addElement(_ name: String, withAttributes attributes: [String: String], caseInsensitive: Bool) -> XMLElement {
let element = XMLElement(name: name, index: count, options: options)
element.parent = self
count += 1

children.append(element)
Expand Down
7 changes: 7 additions & 0 deletions Tests/SWXMLHashTests/XMLParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ struct XMLParsingTests {
#expect(xml!["root"]["catalog"]["book"][1]["author"].element?.text == "Ralls, Kim")
}

@Test
func shouldBeAbleToGetParent() {
#expect(xml!["root"]["catalog"]["book"][1]["author"].element?.parent != nil)
#expect(xml!["root"]["catalog"]["book"][1]["author"].element?.parent?.name == "book")
#expect(xml!["root"]["catalog"]["book"][1]["author"].element?.parent?.attribute(by: "id")?.text == "bk102")
}

@Test
func shouldBeAbleToParseElementGroupsByIndex() {
// swiftlint:disable:next force_try
Expand Down

0 comments on commit 6ae7b83

Please sign in to comment.