v2: Remove Custom field and enhance Extensions for custom elements#251
v2: Remove Custom field and enhance Extensions for custom elements#251
Conversation
BREAKING CHANGE: Remove Item.Custom and Feed.Custom fields entirely
- Remove Custom field from gofeed.Feed and gofeed.Item structs
- Remove Custom field from rss.Item struct
- Update RSS parser to add non-namespaced elements to Extensions under "rss" namespace
- Add support for custom elements at both channel and item level
- Add helper methods for easier access to extensions:
- GetExtension(namespace, element) - returns all matching extensions
- GetExtensionValue(namespace, element) - returns text value of first match
- GetCustomValue(element) - convenience method for RSS custom elements
- Fix RSS parser to skip RDF "items" structural element
- Add comprehensive test coverage for custom element scenarios
- Update existing tests to reflect removal of Custom field
Migration: Replace item.Custom["key"] with item.GetCustomValue("key")
This change allows parsing of custom RSS elements with full attribute
support and nested structure, addressing the limitations of the previous
map[string]string approach.
Fixes #246
Fixes #205 (custom elements now support nested structure and attributes)
Fixes #82 (custom tags like <weight> are now accessible via GetCustomValue)
- Change namespace key from 'rss' to '_custom' to avoid conflicts - '_custom' clearly indicates non-namespaced custom elements - Add custom element support to Atom parser for both feed and entry levels - Update all tests and test data to use '_custom' namespace - Add GetCustomValue helper method for Feed type - Add comprehensive Atom custom element test coverage The '_custom' namespace is less likely to conflict with actual XML namespaces and clearly indicates its special purpose for non-namespaced elements across all feed formats.
|
@infogulch let me know if this change seems fine to you as well. |
|
Looks ok to me. Does this save pagination information like what's described at https://stackoverflow.com/questions/1301392/pagination-in-feeds-like-atom-and-rss ? |
I think this is still fine, if I understand the StackOverflow link correctly. Looking at our Atom parser, we already capture link elements with their rel attributes in the Links field. So pagination links like: These get parsed into the atom.Feed.Links array, where each Link struct has the Href and Rel fields you'd need to follow pagination. So you should be able to access pagination info like: This PR shouldn't change that, as we are only touching the custom fields and these are handled by the standard Link parsing. |
Summary
This PR removes the
Item.Customfield entirely and enhances the existingExtensionsfield to handle all custom and non-standard elements with full structural support including attributes and nested elements. Custom element support has been added to both RSS and Atom parsers.Changes
Customfield fromgofeed.Feedandgofeed.ItemstructsCustomfield fromrss.ItemstructExtensionsunder "_custom" namespaceExtensionsunder "_custom" namespaceBreaking Changes
Item.Customfield removed completelyFeed.Customfield removed completely (if it existed)Migration Guide
Benefits
Test Coverage
Added comprehensive tests for:
Issues Fixed
<weight>are now accessible via GetCustomValue)Example Usage