Skip to content

Instantly share code, notes, and snippets.

@drmohundro drmohundro/example.swift
Last active Mar 9, 2018

Embed
What would you like to do?
Linux namespace and SWXMLHash
let podcastURL = URL(string: "http://feed.thisamericanlife.org/talpodcast")!
let contents = """
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" version="2.0" xml:base="https://www.example.com">
<channel>
<title>Some Title</title>
<link>https://www.example.com</link>
<description>some awesome feed.</description>
<language>en</language>
<copyright>Copyright 1995-3001</copyright>
<itunes:author>John Doe</itunes:author>
<itunes:subtitle>sweet subtitle</itunes:subtitle>
<itunes:owner> <itunes:email>email@example.com</itunes:email>
</itunes:owner>
</channel>
</rss>
"""
let xml2 = SWXMLHash.config { cfg in cfg.shouldProcessNamespaces = true }.parse(contents)
print(contents)
print("-----")
print(xml2.description)
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" version="2.0" xml:base="https://www.example.com">
<channel>
<title>Some Title</title>
<link>https://www.example.com</link>
<description>some awesome feed.</description>
<language>en</language>
<copyright>Copyright 1995-3001</copyright>
<itunes:author>John Doe</itunes:author>
<itunes:subtitle>sweet subtitle</itunes:subtitle>
<itunes:owner> <itunes:email>email@example.com</itunes:email>
</itunes:owner>
</channel>
</rss>
-----
<rss version="2.0" xml:base="https://www.example.com">
<channel>
<title>Some Title</title>
<link>https://www.example.com</link>
<description>some awesome feed.</description>
<language>en</language>
<copyright>Copyright 1995-3001</copyright>
<author>John Doe</author>
<subtitle>sweet subtitle</subtitle>
<owner> <email>email@example.com</email>
</owner>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.