Closed kiri11ko closed 5 years ago
Do you mean to ask this? https://stackoverflow.com/questions/33860624/escaping-strings-in-swift
Yes, I need to check all the value? Does Library no have the function for this case?
How to get all value for the check?
Yes, this library will not handle this case, you can escape the whole XML string for you use case~
OK. Then do not write what you can create XML as it is not. I get XML and add new keys to it, but I need to shovel it all to remake special characters since your library returns just a string.
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: "\<") } }
How to make escaping sequence String from XML? For write-in file and send on the server. Thanks.