我有一个 XML(字符串格式),我想使用 Swift 4 从它获取单个值到字符串变量。
我的数据如下:
let myString ="Adasdnajinasdshabjdbaiusd" //Encrypted Text(Sample)
let MyResult = self.TestObj.decryptData(myString); //Method for Encryption
print(MyResult) // Result in String Format
MyResult 的输出如下:
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><userDetails><status>success</status><name>Ashique</name><role>admin</role></userDetails>
.
这是字符串格式。那么如何在 Swift 4 中将诸如 Name 和 Role 之类的值获取到字符串变量中呢?
提前致谢!
Using XML解析器 https://developer.apple.com/documentation/foundation/xmlparser with:
let parser = XMLParser.init(data: myString.data(using: .utf8))
parser.delegate = self
parser.parse()
继承你的类XML解析延迟 https://developer.apple.com/documentation/foundation/xmlparserdelegate并实现这个:
func parser(parse, element, namespace, name, attributes) {
// check for your element and get attributes.
// ..
}
More here https://www.ioscreator.com/tutorials/parsing-xml-tutorial
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)