[swift-users] XML parsing on Linux, with Swift 3.1
CK TUNG
cktung at mac.com
Tue Sep 5 02:53:16 CDT 2017
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> 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> 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
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/507d095c/attachment.html>
More information about the swift-users
mailing list