chenyunguiMilook / SwiftyXML

The most swifty way to deal with XML data in swift 5.
MIT License
103 stars 28 forks source link

For make true XML need in the loop get all value and fix then. #9

Closed kiri11ko closed 5 years ago

kiri11ko commented 5 years ago

For make true XML need in the loop get all value and fix then. Example: let newXMLHead: XML = XML(name: "clients") let usersXML: [XML] = memoryXML!["#clients"]["client"].xmlList! for value in usersXML { let newXML: XML = XML(name: "clients") for (key, subValue) in value.attributes { newXML.addAttribute(name: key, value: subValue.percentEscapeString()) } newXMLHead.addChild(newXML) }

Where extension String { func percentEscapeString() -> String { return self .replacingOccurrences(of: "&", with: "\&") .replacingOccurrences(of: "\"", with: "\"") .replacingOccurrences(of: "'", with: "\'") .replacingOccurrences(of: ">", with: "\>") .replacingOccurrences(of: "<", with: "\<") } }

Originally posted by @kiri11ko in https://github.com/chenyunguiMilook/SwiftyXML/issues/8#issuecomment-511768551

chenyunguiMilook commented 5 years ago

@kiri11ko, thanks for bringing this up, I will schedule to implement this recently.

chenyunguiMilook commented 5 years ago

@kiri11ko I have fixed this issue