当试图解析XML时, CR / LF字符转换



我正在尝试操作XML文档。我正在使用AEXML。

其中一个元素是:

<DigestValue>MDEwDQYJYIZIAWUDBAIBBQAEINw11if3rwKZpjXua6DautZ/ciHeGATrbbGRpeoE&#xD;
83NQ</DigestValue>

它被改成:

<DigestValue>MDEwDQYJYIZIAWUDBAIBBQAEINw11if3rwKZpjXua6DautZ/ciHeGATrbbGRpeoE
&#10;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: "&amp;", options: .literal)
/// replace the other five special characters
let escapeChars = ["r": "&#xD;"]

for (char, echar) in escapeChars {
escaped = escaped.replacingOccurrences(of: char, with: echar, options: .literal)
}

return escaped
}
}

最新更新