Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make escaping sequence String from xml? #8

Closed
kiri11ko opened this issue Jul 12, 2019 · 6 comments
Closed

How to make escaping sequence String from xml? #8

kiri11ko opened this issue Jul 12, 2019 · 6 comments

Comments

@kiri11ko
Copy link

How to make escaping sequence String from XML? For write-in file and send on the server. Thanks.

@chenyunguiMilook
Copy link
Owner

@kiri11ko
Copy link
Author

Yes, I need to check all the value?
Does Library no have the function for this case?

@kiri11ko
Copy link
Author

How to get all value for the check?

@chenyunguiMilook
Copy link
Owner

Yes, this library will not handle this case, you can escape the whole XML string for you use case~

@kiri11ko
Copy link
Author

kiri11ko commented Jul 15, 2019

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.

@kiri11ko
Copy link
Author

kiri11ko commented Jul 16, 2019

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: "&lt;")
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants