[swift-users] XML parsing on Linux, with Swift 3.1

Georgios Moschovitis george.moschovitis at icloud.com
Tue Sep 5 03:19:15 CDT 2017


Indeed it works, but I don’t get it.
What’s the difference?

-g.

PS: Btw, my original code was giving `seg-fault: 11` even on macOS.

> On 5 Sep 2017, at 10:53 AM, CK TUNG via swift-users <swift-users at swift.org> wrote:
> 
> This revised code, as below, works without segmentation fault
> 
> import Foundation
> 
> class ParserDelegate: NSObject, XMLParserDelegate {
>     
>     func startParsing(_ xml:String) {
>         let data = xml.data(using: .utf8)!
>         let xmlParser = XMLParser(data: data)
>         xmlParser.delegate = self
>         xmlParser.parse()
>     }
>     
>     func parserDidStartDocument(_ parser: XMLParser) {
>         print("Starting document")
>     }
>     
>     func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
>         print("*** \(elementName)")
>     }
> }
> 
> let xml = "<root><title name=\"test\">George</title></root>"
> let test = ParserDelegate()
> test.startParsing(xml)
> 
> On Sep 05, 2017, at 02:24 PM, Georgios Moschovitis via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> 
>> As an example, this SegFaults:
>> 
>> import Foundation
>> 
>> class ParserDelegate: NSObject, XMLParserDelegate {
>> func parserDidStartDocument(_ parser: XMLParser) {
>> print("Starting document")
>> }
>> 
>> func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
>> print("*** \(elementName)")
>> }
>> }
>> 
>> let xml = "<root><title name=\"test\">George</title></root>"
>> let data = xml.data(using: .utf8)!
>> let xmlParser = XMLParser(data: data)
>> xmlParser.delegate = ParserDelegate()
>> xmlParser.parse()
>> 
>>> On 5 Sep 2017, at 9:01 AM, Georgios Moschovitis <george.moschovitis at icloud.com <mailto:george.moschovitis at icloud.com>> wrote:
>>> 
>>> Hi,
>>> 
>>> I would like to parse an RSS feed using Swift 3.1 on Linux.
>>> I tried to use Foundations’s XML but I only managed to get segmentation faults.
>>> Is this supposed to work on Linux? I have only seen examples on iOS.
>>> 
>>> Apart from that a quick search didn’t reveal any useful XML parsing library compatible with Linux.
>>> 
>>> Any suggestions?
>>> 
>>> -g.
>> 
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org <mailto:swift-users at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170905/8c480069/attachment.html>


More information about the swift-users mailing list