Hi All, Im currently doing XML passing on Mac and ...
# kotlin-native
s
Hi All, Im currently doing XML passing on Mac and passing the actual parsing off to NSXML as follows
Copy code
actual fun parse(xml: String) {

    xml.usePinned {
        val bytes = it.get().encodeToByteArray()
        val pointer = StableRef.create(bytes)
        val data = NSData.dataWithBytes(pointer.asCPointer(), bytes.size.toULong())
        this.parser = NSXMLParser(data = data)
        this.parser.delegate = this
        this.parser.parse()
    }

    this.parser.setDelegate(null)

    println("Parsing Done")
}
Delegate get called for start doc but then parsing fails with NSXMLParserErrorDomain error 4. which would indicate the NSData was empty but it doesnt appear to be the case, is there something Im missing?
Ok so apparently I was trying to hard - resolved the issue after finding usePinned in the docs.
Copy code
actual fun parse(xml: String) {

    val bytes = xml.encodeToByteArray()

    this.usePinned { parserRef ->
        bytes.usePinned { xmlRef ->
            val data = NSData.dataWithBytes(xmlRef.addressOf(0), bytes.size.convert())
            this.parser = NSXMLParser(data = data)
            this.parser.delegate = this
            this.parser.parse()
        }
    }

    this.parser.setDelegate(null)

    println("Parsing Done")
}