diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fbb2d17..9918ecae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v4.6.0 (March 10, 2018) + +* Added XML validation config option (via + [#169](https://github.com/drmohundro/SWXMLHash/pull/169) and + [#141](https://github.com/drmohundro/SWXMLHash/issues/141)) + ## v4.5.1 (March 8, 2018) * Swift 4.1 deprecation warnings silenced (via diff --git a/README.md b/README.md index e15c3e7a..96d85256 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,11 @@ The available options at this time are: * See [Codable's userInfo docs](https://developer.apple.com/documentation/swift/encoder/2894907-userinfo) * The default is [:] +* `detectParsingErrors` + * This setting attempts to detect XML parsing errors. `parse` will return an + `XMLIndexer.parsingError` if any parsing issues are found. + * Defaults to `false` (because of backwards compatibility and because many + users attempt to parse HTML with this library) ## Examples diff --git a/SWXMLHash.podspec b/SWXMLHash.podspec index 013bca4c..c3541545 100644 --- a/SWXMLHash.podspec +++ b/SWXMLHash.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'SWXMLHash' - s.version = '4.5.1' + s.version = '4.6.0' s.summary = 'Simple XML parsing in Swift' s.homepage = 'https://github.com/drmohundro/SWXMLHash' s.license = { type: 'MIT' } diff --git a/SWXMLHash.xcodeproj/project.pbxproj b/SWXMLHash.xcodeproj/project.pbxproj index b27b237e..3579d1ac 100644 --- a/SWXMLHash.xcodeproj/project.pbxproj +++ b/SWXMLHash.xcodeproj/project.pbxproj @@ -481,7 +481,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0930; TargetAttributes = { CD6083EE196CA106000B4F8D = { CreatedOnToolsVersion = 6.0; @@ -725,12 +725,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -785,12 +787,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; diff --git a/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash OSX.xcscheme b/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash OSX.xcscheme index 600fd7cd..bf88f2e9 100644 --- a/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash OSX.xcscheme +++ b/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash OSX.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -57,7 +56,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash iOS.xcscheme b/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash iOS.xcscheme index c2c304ea..e08a6eda 100644 --- a/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash iOS.xcscheme +++ b/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash iOS.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -57,7 +56,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash tvOS.xcscheme b/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash tvOS.xcscheme index fe0d9c1a..115ed368 100644 --- a/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash tvOS.xcscheme +++ b/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash tvOS.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -57,7 +56,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash watchOS.xcscheme b/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash watchOS.xcscheme index 06850908..fe2697dd 100644 --- a/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash watchOS.xcscheme +++ b/SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash watchOS.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -38,7 +37,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SWXMLHash.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SWXMLHash.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/SWXMLHash.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Source/SWXMLHash.swift b/Source/SWXMLHash.swift index 60304cc8..f42dfa16 100644 --- a/Source/SWXMLHash.swift +++ b/Source/SWXMLHash.swift @@ -473,10 +473,10 @@ public class IndexOps { parser.startParsing(ops) let indexer = XMLIndexer(parser.root) var childIndex = indexer - for op in ops { - childIndex = childIndex[op.key] - if op.index >= 0 { - childIndex = childIndex[op.index] + for oper in ops { + childIndex = childIndex[oper.key] + if oper.index >= 0 { + childIndex = childIndex[oper.index] } } ops.removeAll(keepingCapacity: false) @@ -484,11 +484,11 @@ public class IndexOps { } func stringify() -> String { - var s = "" - for op in ops { - s += "[" + op.toString() + "]" + var ret = "" + for oper in ops { + ret += "[" + oper.toString() + "]" } - return s + return ret } } @@ -723,8 +723,8 @@ public enum XMLIndexer { public func byKey(_ key: String) throws -> XMLIndexer { switch self { case .stream(let opStream): - let op = IndexOp(key) - opStream.ops.append(op) + let oper = IndexOp(key) + opStream.ops.append(oper) return .stream(opStream) case .element(let elem): let match = elem.xmlChildren.filter({ @@ -915,6 +915,12 @@ public class XMLElement: XMLContent { }) } + public var innerXML: String { + return children.reduce("", { + return $0.description + $1.description + }) + } + /// All child elements (text or XML) public var children = [XMLContent]() diff --git a/Tests/SWXMLHashTests/XMLParsingTests.swift b/Tests/SWXMLHashTests/XMLParsingTests.swift index 49c20a87..aba6adfe 100644 --- a/Tests/SWXMLHashTests/XMLParsingTests.swift +++ b/Tests/SWXMLHashTests/XMLParsingTests.swift @@ -205,6 +205,13 @@ class XMLParsingTests: XCTestCase { XCTAssertEqual(parsed.description, "puppies") } + func testShouldBeAbleToGetInnerXML() { + let testXML = "puppies12" + let parsed = SWXMLHash.parse(testXML) + + XCTAssertEqual(parsed["root"]["foo"].element!.innerXML, "puppies12") + } + // error handling func testShouldReturnNilWhenKeysDontMatch() {