我正在尝试操作XML文档。我正在使用AEXML。
其中一个元素是:
<DigestValue>MDEwDQYJYIZIAWUDBAIBBQAEINw11if3rwKZpjXua6DautZ/ciHeGATrbbGRpeoE
83NQ</DigestValue>
它被改成:
<DigestValue>MDEwDQYJYIZIAWUDBAIBBQAEINw11if3rwKZpjXua6DautZ/ciHeGATrbbGRpeoE
83NQ</DigestValue>
如何保留字符串表示?
我更改了AEXMLElement类的xmlEscaped
函数。
public extension String {
/// String representation of self with XML special characters escaped.
var xmlEscaped: String {
/// we need to make sure "&" is escaped first. Not doing this may break escaping the other characters
var escaped = replacingOccurrences(of: "&", with: "&", options: .literal)
/// replace the other five special characters
let escapeChars = ["r": "
"]
for (char, echar) in escapeChars {
escaped = escaped.replacingOccurrences(of: char, with: echar, options: .literal)
}
return escaped
}
}