Saturday, 6 December 2014

Swift XML parser randomly remove white spaces



I'm parsing a big XML file with french text in Swift and there are some white spaces randomly removed when I retrieve nodes values from it.


Here's the file (open-source, more than 5mb): http://ift.tt/1tYiMEh


Randomly, white spaces are removed just before accentuated characters. For instance, here's a line from the XML:



<dictScrap>Entre un substantif et un verbe. L'exhortation <oVar>à</oVar> combattre. L'encouragement <oVar>à</oVar> bien vivre. La disposition <oVar>à</oVar> plaisanter. La promptitude <oVar>à</oVar> faire. L'habileté <oVar>à</oVar> parler. La facilité <oVar>à</oVar> comprendre. La répugnance <oVar>à</oVar> venir. Le plaisir <oVar>à</oVar> obéir. La fermeté <oVar>à</oVar> soutenir la vérité. La honte <oVar>à</oVar> mentir.</dictScrap>


And here's the line after parsing:



Optional("Entre un substantif et un verbe. L\'exhortationà combattre. L\'encouragement à bien vivre. La disposition à plaisanter. La promptitude à faire. L\'habileté à parler. La facilité à comprendre. La répugnance à venir. Le plaisir à obéir. La fermeté à soutenir la vérité. La honte à mentir.")


Notice that white space before the first à disappeared, but not the others.


I removed all the <oVar> with search-replace with my editor, didn't need those and got lazy trying to do it with code.


I'm using AEXML for parsing: http://ift.tt/1wbuuSF


Here's my code, which doesn't do anything but taking the string and printing it:



if sense["dictScrap"].count > 0 {
senseEntity.value = sense["dictScrap"].value
}

println(senseEntity.value)


Thanks for your help!


No comments:

Post a Comment