Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to decode <itunes:episode> tags #201

Closed
RichardAtDP opened this issue Sep 14, 2020 · 4 comments
Closed

How to decode <itunes:episode> tags #201

RichardAtDP opened this issue Sep 14, 2020 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@RichardAtDP
Copy link

How would one go about decoding a tag with a colon in it, for example:

itunes:episode544</itunes:episode>

Thanks

@MaxDesiatov MaxDesiatov added the question Further information is requested label Sep 14, 2020
@MaxDesiatov
Copy link
Collaborator

Hi @RichardAtDP, the colon in the name denotes the presence of the itunes namespace. You could strip it with the shouldProcessNamespaces property on XMLDecoder, as described in README.md. Does that answer your question?

@RichardAtDP
Copy link
Author

Thanks @MaxDesiatov - I'm wondering how to integrate that option in a Combine pipeline?

@MaxDesiatov
Copy link
Collaborator

Did you check the existing section about Combine? The decoding operator takes a decoder instance as an argument, you can pass your own with shouldProcessNamespaces set as needed.

@RichardAtDP
Copy link
Author

RichardAtDP commented Sep 14, 2020

Got it! Thanks for your help.

For reference

let decoder = XMLDecoder();
decoder.shouldProcessNamespaces = true

self.cancellable = URLSession.shared.dataTaskPublisher(for: url)
            .map {  $0.data }
            .decode(type: Response.self, decoder: decoder )
            .catch { err in
                return Just( Response(info:info), error: "\(err)") )
            }
           .replaceError(with: Response(info:info), error: "\(err)") )
           .receive(on: DispatchQueue.main)
           .eraseToAnyPublisher()
           .assign(to: \.response, on: self)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants