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)
}
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