I am trying to get the value of an attribute in an XML Node in swift. The following is a code example. I don't see any way of getting the value as no properties or methods seem to allow for this.
for word in dictionary.words {
let xpath = "/strongsdictionary/entries/entry[greek[@unicode='" + word.word + "']]/pronunciation"
do {
let xmlnode = try document?.nodes(forXPath: xpath )
// Need to get value of attribute named 'strongs' from the node here.
} catch {
debugPrint("Error finding xpath path.")
break
}
}
xmlnodeis an array ofXMLNode. Iterate the array of nodes. If your xpath returns elements, then cast each node to anXMLElement. From the element you can get the its attributes.You can combine the three
if letinto one but the above is easier to debug.