parser.go 734 B

12345678910111213141516171819202122232425262728
  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 // import "miniflux.app/reader/opml"
  5. import (
  6. "encoding/xml"
  7. "io"
  8. "miniflux.app/errors"
  9. "miniflux.app/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.Entity = xml.HTMLEntity
  16. decoder.CharsetReader = encoding.CharsetReader
  17. err := decoder.Decode(feeds)
  18. if err != nil {
  19. return nil, errors.NewLocalizedError("Unable to parse OPML file: %q", err)
  20. }
  21. return feeds.Transform(), nil
  22. }