import Foundation let xmlString = """ """ if let xmlData = xmlString.data(using: .utf8) { do { let doc = try XMLDocument(data: xmlData) print("Using XPath:") for node in try doc.nodes(forXPath: "/Students/Student/@Name") { guard let name = node.stringValue else { continue } print(name) } print("Using node walk") if let root = doc.rootElement() { for child in root.elements(forName: "Student") { guard let name = child.attribute(forName: "Name")?.stringValue else { continue } print(name) } } } catch { debugPrint(error) } }