You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a very strange problem. My goal is to load a simple XML file from the web. I am downloading data and cleaning it. At the end, my app tries to parse it with a specific model. When the app is running, I am getting an error: The operation couldn’t be completed. (NSXMLParserErrorDomain error 111.). When I make a breakpoint on decode(_:) function and call the same method in lldb everything is working, and I am getting the result.
I am removing <content> tags because sample code breaks decoder.
func dataMiddleware(_ data:Data)->Data{letstringData=String(data: data, encoding:.utf8)?.replacingOccurrences(of:"(<content:encoded>)([\\s\\S]*?)(</content:encoded>)", with:"", options:.regularExpression)return stringData?.data(using:.utf8)?? data
}
After this transformation this specific xml looks like:
<?xml version = "1.0" encoding="UTF-8"?>
<rssversion="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>WWDC NOTES</title>
<description>Open-source and community-driven effort to collect notes for all Apple's WWDC videos. ❤️</description>
<link>https://www.wwdcnotes.com</link>
<language>en</language>
<lastBuildDate>Sun, 3 Sep 2023 20:06:50 +0200</lastBuildDate>
<pubDate>Sun, 3 Sep 2023 20:06:50 +0200</pubDate>
<ttl>250</ttl>
<atom:linkhref="https://www.wwdcnotes.com/feed.rss"rel="self"type="application/rss+xml"/>
<item>
<guidisPermaLink="true">https://www.wwdcnotes.com/notes/wwdc23/10257</guid>
<title>Create animated symbols</title>
<description>Discover animation presets and learn how to use them with SF Symbols and custom symbols. We'll show you how to experiment with different options and configurations to find the perfect animation for your app. Learn how to update custom symbols for animation using annotation features, find out how to modify your custom symbols with symbol components, and explore the redesigned export process to help keep symbols looking great on all platforms.
To get the most out of this session, check out “What’s new in SF Symbols 5” from WWDC23.</description>
<link>https://www.wwdcnotes.com/notes/wwdc23/10257</link>
<pubDate>Sun, 3 Sep 2023 16:38:00 +0200</pubDate>
</item>
</channel>
</rss>
Next I am decoding the data into model:
letfeed=try decoder.decode(SomeModel.self, from:dataMiddleware(data))structSomeModel{letchannel:ChannelstructChannel:Codable{enumCodingKeys:String,CodingKey{case title, link, lastBuildDate
case items ="item"}lettitle:Stringletlink:URLletlastBuildDate:Dateletitems:[Item]structItem:Codable{lettitle:Stringletlink:URLletguid:StringletpubDate:Date}}}
Results
When I am calling lldb command I am getting proper output:
The same code is running in Vapor scope and the same function throws an error:
[ INFO ] The operation couldn’t be completed. (NSXMLParserErrorDomain error 111.) (App/Service.swift:46)
[ WARNING ] Error Domain=NSXMLParserErrorDomain Code=111 "(null)" (App/services.swift:35)
Summary
I can not find anything that helps me to solve this problem. Error 111 looks like it indicates a bad data structure but these work properly during debugging.
The text was updated successfully, but these errors were encountered:
Hi everybody!
I found a very strange problem. My goal is to load a simple XML file from the web. I am downloading data and cleaning it. At the end, my app tries to parse it with a specific model. When the app is running, I am getting an error:
The operation couldn’t be completed. (NSXMLParserErrorDomain error 111.)
. When I make a breakpoint ondecode(_:)
function and call the same method in lldb everything is working, and I am getting the result.How to reproduce
So, for example. I am getting XML data from some source. Could be this for our purposes: https://www.wwdcnotes.com/feed.rss
I am removing
<content>
tags because sample code breaks decoder.Results
Summary
I can not find anything that helps me to solve this problem. Error 111 looks like it indicates a bad data structure but these work properly during debugging.
The text was updated successfully, but these errors were encountered: