1

I am using SWXMLHash for parsing the data from server. It crashes when I have &amp in my data.

let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
let str = responseString as! String
let xml = SWXMLHash.parse(str)
//let xml = SWXMLHash.parse(data!)
print("responseString = \(xml)") 

It does not parse the whole data. It stops where there is &amp or &.

Shaheera
  • 307
  • 1
  • 15
  • I've never had this kind of issue with [Fuzi](https://github.com/cezheng/Fuzi), it may be worth trying. – Eric Aya Aug 23 '16 at 12:36
  • Are you sure I wont have any problem? Because I will have to change it in the whole project. I just came through this problem. – Shaheera Aug 23 '16 at 12:48
  • Well I certainly don't suggest to change all your codebase without testing first. :) I would make a new test project, include Fuzi, and simply use it quickly to parse your data and see if it works. If it works better than SWXMLHash (I suppose so but I have no *proof*) then you can change your actual project. Don't forget to use Git and to also backup first, of course. – Eric Aya Aug 23 '16 at 12:51
  • Thank you so much... I will test it first with my data. – Shaheera Aug 23 '16 at 13:03
  • I checked it. It does not crash but it is inserting space instead of & :( – Shaheera Aug 23 '16 at 15:06
  • Ampersands shouldn't cause any issues with SWXMLHash... are you sure it isn't some other character? BOM (byte order marks) do have problems with `NSXMLParser` which is what SWXMLHash uses. – David Mohundro Aug 23 '16 at 18:29
  • I didn't try NSXMLParser. But yes, the issue was with & Only. – Shaheera Aug 24 '16 at 04:52
  • You might try passing data directly to SWXMLHash like SWXMLHash.parse(data!) or better yet guard let data = data else { return } SWXMLHash.parse(data) – Brian F Leighty Aug 24 '16 at 20:53
  • I have tried this as well. – Shaheera Aug 25 '16 at 07:28

0 Answers0