I want to convert an XML string into a tuple.
var responseXml =
"""
<?xml version="1.0"?>
<tmweb>
<booking type='come' time='71102' persnr='9999' name='Test' firstname='Max' title='Mr.'/>
</tmweb>
"""
responseXml.removeFirst(39) // Remove the beginning of the XML
responseXml.removeLast(11) // Remove the end of the XML
responseXml = responseXml.replacingOccurrences(of:" ", with: ";") // Replace empty place with ;
responseXml = responseXml.replacingOccurrences(of: "'", with: "\"") // Replace ' to "
responseXml = responseXml.replacingOccurrences(of: "=", with: ": ") // Replace = to :(space)
Temporary output:
"type: "come";time: "71102";persnr: "9999";name: "Test";firstname: "Max";title: "Mr."\n"
At the moment I only have the whole string as with the replacements as a UIAlert
My next steps:
I want to convert the seconds (71102) to readable time format like 19:45:22
func secs2time (_ seconds : Int) -> (Int,Int,Int) {
return (seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60)
}
At the moment it's hard to find a good solution.
Any suggestions?