parser.go 696 B

123456789101112131415161718192021222324252627
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package opml
  5. import (
  6. "encoding/xml"
  7. "io"
  8. "github.com/miniflux/miniflux/errors"
  9. "github.com/miniflux/miniflux/reader/encoding"
  10. )
  11. // Parse reads an OPML file and returns a SubcriptionList.
  12. func Parse(data io.Reader) (SubcriptionList, *errors.LocalizedError) {
  13. feeds := new(opml)
  14. decoder := xml.NewDecoder(data)
  15. decoder.CharsetReader = encoding.CharsetReader
  16. err := decoder.Decode(feeds)
  17. if err != nil {
  18. return nil, errors.NewLocalizedError("Unable to parse OPML file: %q", err)
  19. }
  20. return feeds.Transform(), nil
  21. }