jaywcjlove/swift-opml
OPML
Installation
Swift Package Manager
Add CodeMirror to your project using Xcode:
- In Xcode, go to
File→Add Package Dependencies... - Enter the repository URL:
https://github.com/jaywcjlove/swiftui-opml.git - Click
Add Package
Or add it to your Package.swift file:
dependencies: [
.package(url: "https://github.com/jaywcjlove/swiftui-opml.git", from: "1.0.0")
]Usage
Parsing OPML Files
The library supports parsing OPML files from both file URLs and raw data. Use the convenient static methods or create a parser instance for more control:
From File URL
import OPML
// Static convenience method
let opml = try OPMLParser.parse(contentsOf: fileURL)
// Or using a parser instance
let parser = try OPMLParser(contentsOf: fileURL)
let opml = try parser.parse()
// OPML(version: "2.0", title: Optional("Feedly"), ...From Data
// Static convenience method
let data = xmlString.data(using: .utf8)!
let opml = try OPMLParser.parse(data: data)
// OPML(version: "2.0", title: Optional("Feedly"), ...
// Or using a parser instance
let parser = try OPMLParser(data: data)
let opml = try parser.parse()
// OPML(version: "2.0", title: Optional("Feedly"), ...Creating and Generating OPML Files
You can programmatically create OPML documents and convert them to XML. This is useful for generating subscription lists, organizing feeds into categories, or creating OPML exports from your application.
import OPML
let opml = OPML(
title: "Test OPML with Nested Outlines",
ownerName: "Test User",
outlines: [
OPML.Outline(
text: "Technology",
title: "Technology",
children: [
OPML.Outline(
text: "Apple News",
title: "Apple News",
attributes: [
.init(name: "xmlUrl", value: "https://apple.com/rss"),
.init(name: "htmlUrl", value: "https://apple.com")
]
),
OPML.Outline(
text: "Swift Blog",
title: "Swift Blog",
attributes: [
.init(name: "xmlUrl", value: "https://swift.org/rss"),
.init(name: "htmlUrl", value: "https://swift.org")
]
)
]
)
]
)Use the toXMLString() method to convert an OPML object to a properly formatted XML string:
let xmlString = opml.toXMLString()This generates well-formatted XML output:
<opml version="2.0">
<head>
<title>Test OPML with Nested Outlines</title>
<dateCreated>Tue, 16 Dec 2025 17:18:28 +0800</dateCreated>
<ownerName>Test User</ownerName>
<docs>https://opml.org/spec2.opml</docs>
</head>
<body>
<outline text="Technology" title="Technology">
<outline
text="Apple News"
title="Apple News"
xmlUrl="https://apple.com/rss"
htmlUrl="https://apple.com"
/>
<outline
text="Swift Blog"
title="Swift Blog"
xmlUrl="https://swift.org/rss"
htmlUrl="https://swift.org"
/>
</outline>
</body>
</opml>Acknowledgments
Thanks to these projects:
https://github.com/pixel-foundry/opml
License
Licensed under the MIT License.
Package Metadata
Repository: jaywcjlove/swift-opml
Default branch: main
README: README.md