File tree 2 files changed +23
-10
lines changed 2 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -473,22 +473,22 @@ public class IndexOps {
473
473
parser. startParsing ( ops)
474
474
let indexer = XMLIndexer ( parser. root)
475
475
var childIndex = indexer
476
- for op in ops {
477
- childIndex = childIndex [ op . key]
478
- if op . index >= 0 {
479
- childIndex = childIndex [ op . index]
476
+ for oper in ops {
477
+ childIndex = childIndex [ oper . key]
478
+ if oper . index >= 0 {
479
+ childIndex = childIndex [ oper . index]
480
480
}
481
481
}
482
482
ops. removeAll ( keepingCapacity: false )
483
483
return childIndex
484
484
}
485
485
486
486
func stringify( ) -> String {
487
- var s = " "
488
- for op in ops {
489
- s += " [ " + op . toString ( ) + " ] "
487
+ var ret = " "
488
+ for oper in ops {
489
+ ret += " [ " + oper . toString ( ) + " ] "
490
490
}
491
- return s
491
+ return ret
492
492
}
493
493
}
494
494
@@ -723,8 +723,8 @@ public enum XMLIndexer {
723
723
public func byKey( _ key: String ) throws -> XMLIndexer {
724
724
switch self {
725
725
case . stream( let opStream) :
726
- let op = IndexOp ( key)
727
- opStream. ops. append ( op )
726
+ let oper = IndexOp ( key)
727
+ opStream. ops. append ( oper )
728
728
return . stream( opStream)
729
729
case . element( let elem) :
730
730
let match = elem. xmlChildren. filter ( {
@@ -915,6 +915,12 @@ public class XMLElement: XMLContent {
915
915
} )
916
916
}
917
917
918
+ public var innerXML : String {
919
+ return children. reduce ( " " , {
920
+ return $0. description + $1. description
921
+ } )
922
+ }
923
+
918
924
/// All child elements (text or XML)
919
925
public var children = [ XMLContent] ( )
920
926
Original file line number Diff line number Diff line change @@ -205,6 +205,13 @@ class XMLParsingTests: XCTestCase {
205
205
XCTAssertEqual ( parsed. description, " <root><foo><what id= \" myId \" >puppies</what></foo></root> " )
206
206
}
207
207
208
+ func testShouldBeAbleToGetInnerXML( ) {
209
+ let testXML = " <root><foo><what id= \" myId \" >puppies</what><elems><elem>1</elem><elem>2</elem></elems></foo></root> "
210
+ let parsed = SWXMLHash . parse ( testXML)
211
+
212
+ XCTAssertEqual ( parsed [ " root " ] [ " foo " ] . element!. innerXML, " <what id= \" myId \" >puppies</what><elems><elem>1</elem><elem>2</elem></elems> " )
213
+ }
214
+
208
215
// error handling
209
216
210
217
func testShouldReturnNilWhenKeysDontMatch( ) {
You can’t perform that action at this time.
0 commit comments