Closed bigtrade2017 closed 2 years ago
@bigtrade2017 Thank you for your reporting. I checked the code snippet on Xcode 11.5, Swift 5.2.4, and I didn't get the compiler error.
But I found some mistakes in your code. First, you need to add "do-try-catch" around XML.parse(:_). Second, XML has the root element. The document is illegal.
Could you check that?
Hi, please try this one:
let buffer = """
<root>
<otherElement>…</otherElement>
<myElement><test1></test1></myElement>
<otherElement>…</otherElement>
<otherElement>…</otherElement>
<myElement><test2></test2></myElement>
<otherElement>…</otherElement>
<myElement><test3></test3></myElement>
</root>
""".data(using: .utf8)!
let xml = XML.parse(buffer)
//xml.root.myElement.flatMap { $0 } //<--- illegal instruction 4
//let map = xml.root.myElement.map { $0 } // ok
let filter = xml.root.element?.childElements.filter { $0.name == "myElement" }.forEach {
print($0.name)
}// ok, but not so nice
//for element in xml.root.myElement {
// print(element.name)
//} //<--- illegal instruction 4
//xml.root.myElement.forEach { element in
// print(element.name)
//} //<--- illegal instruction 4
And, maybe it's possible to add to existing data somehow?
For example, like this:
let buffer2 = buffer
let xml2 = XML.parse(buffer2)
let _xml = xml + xml2
//or like this:
xml.add(xml2)
Hey, have you tried?:)
I'm sorry for being late. I'll try soom 🙌
I executed the code on Xcode12 and Swift5.3. It worked fine. Could you try on the environment?
I'm using Xcode 11.5 & Swift 5.2.4. Trying to parse xml like:
I want to access sequence ("_elementIneed"), but project doesn't get compiled and Xcode suggests to report a bug.