From ea495d1fe3cdbe82f4616078110a10a232be39a0 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 13 Sep 2024 19:35:18 -0700 Subject: [PATCH] Continue progress on AtomParser. --- .../FeedParser/Feeds/XML/AtomParser.swift | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Modules/Parser/Sources/FeedParser/Feeds/XML/AtomParser.swift b/Modules/Parser/Sources/FeedParser/Feeds/XML/AtomParser.swift index 5929d03ab..292d883ea 100644 --- a/Modules/Parser/Sources/FeedParser/Feeds/XML/AtomParser.swift +++ b/Modules/Parser/Sources/FeedParser/Feeds/XML/AtomParser.swift @@ -21,11 +21,21 @@ final class AtomParser { } private let feed: RSSFeed + private var articles = [RSSArticle]() private var currentArticle: RSSArticle? { articles.last } + private var attributesStack = [SAXParser.XMLAttributesDictionary]() + private var currentAttributes: SAXParser.XMLAttributesDictionary? { + attributesStack.last + } + + private var parsingArticle = false + private var parsingXHTML = false + private var endFeedFound = false + static func parsedFeed(with parserData: ParserData) -> RSSFeed { let parser = AtomParser(parserData) @@ -48,6 +58,11 @@ private extension AtomParser { feed.articles = articles } + func addArticle() { + let article = RSSArticle(feedURL) + articles.append(article) + } + } @@ -55,6 +70,24 @@ extension AtomParser: SAXParserDelegate { public func saxParser(_ saxParser: SAXParser, xmlStartElement localName: XMLPointer, prefix: XMLPointer?, uri: XMLPointer?, namespaceCount: Int, namespaces: UnsafePointer?, attributeCount: Int, attributesDefaultedCount: Int, attributes: UnsafePointer?) { + if endFeedFound { + return + } + + let xmlAttributes = saxParser.attributesDictionary(attributes, attributeCount: attributeCount) ?? SAXParser.XMLAttributesDictionary() + attributesStack.append(xmlAttributes) + + if parsingXHTML { +// addXHTMLTag(localName) + return + } + +// if SAXEqualTags(localName, "entry") { +// parsingArticle = true +// addArticle() +// return +// } + } public func saxParser(_ saxParser: SAXParser, xmlEndElement localName: XMLPointer, prefix: XMLPointer?, uri: XMLPointer?) {