0

I need your help to sort my problem out, coding with Swift on XCode 14.1 :

When trying to parse an XML file, I noticed that most of values are not trimmed and appears in the XML file with some trailing spaces such as name="ABC " and number of spaces is not always the same. It's randomely from 3 to 6 or 7 spaces.

For example, when I execute the following code :

let subIndexer = xml["Objects"]["Points"]["Point"]
.filterAll { elem, _ in elem.attribute(by: "name")!.text  == "ABC" }

...it doesn't find my element of course as it's "ABC " in the XML. How can I do ?

I thank you in advance !

mzjn
  • 48,958
  • 13
  • 128
  • 248
hgiraud
  • 23
  • 3
  • Sorry, I forgot to mention language is Swift – hgiraud Dec 10 '22 at 15:33
  • Not really, sorry. I am a newbie and cannot figure out the way to implement it. I read also something about String.trimmingCharacters but cannot figure out either – hgiraud Dec 10 '22 at 15:53
  • Just implement the first answer in the linked question to `text` – Joakim Danielson Dec 10 '22 at 16:20
  • I tried with : .filterAll { elem, _ in elem.attribute(by: "name")!.text.trimmingCharacters(in: .whitespaces) == "TOC" } but still cannot find my element. Did I implement wrongly the syntax ? – hgiraud Dec 10 '22 at 16:31
  • It looks right but I don’t know what filterAll does and if there is something else that is incorrect – Joakim Danielson Dec 10 '22 at 16:39
  • Alright, thank you ! So if the syntax is correct, it means my problem is somewhere else. Appreciate your help all – hgiraud Dec 10 '22 at 16:48

0 Answers0