shared

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CDATA_END = "]]>"
View Source
const CDATA_START = "<![CDATA["

Variables

This section is empty.

Functions

func DecodeEntities

func DecodeEntities(str string) string

DecodeEntities decodes escaped XML entities in a string and returns the unescaped string

func FindRoot added in v1.2.1

func FindRoot(p *xpp.Parser) (event xpp.EventType, err error)

FindRoot iterates through the tokens of an xml document until it encounters its first StartTag event. It returns an error if it reaches EndDocument before finding a tag.

func ForEachChild added in v1.4.0

func ForEachChild(p *xpp.Parser, handle func(name string) error) error

ForEachChild advances through the children of the element the parser is currently on, calling handle for each child start tag with its lowercased local name. handle must fully consume the child element, by parsing or skipping it. ForEachChild returns once it reaches the enclosing element's end tag, leaving the parser on it, so callers can assert it with Expect.

func IsExtension

func IsExtension(p *xpp.Parser) bool

IsExtension returns whether or not the current XML element is an extension element (if it has a non empty prefix)

func NewControlCharFilterReader added in v1.4.0

func NewControlCharFilterReader(r io.Reader) io.Reader

NewControlCharFilterReader wraps r and drops the C0 control bytes that are illegal in XML (bytes below 0x20 other than tab, LF, and CR). Those byte values are identical across UTF-8 and the single-byte encodings feeds use, and never occur inside a multi-byte UTF-8 sequence, so filtering them on the raw stream is safe regardless of the declared encoding. This lets feeds with stray control characters parse instead of failing outright.

func NewReaderLabel

func NewReaderLabel(label string, input io.Reader) (io.Reader, error)

func NewXMLParser added in v1.4.0

func NewXMLParser(r io.Reader) *xpp.Parser

NewXMLParser returns a pull parser configured the way every gofeed parser needs it: non-strict, so real-world feeds with unescaped entities and other common mistakes still tokenize, and with charset conversion for feeds that declare a non-UTF-8 encoding.

func NextTag added in v1.2.1

func NextTag(p *xpp.Parser) (event xpp.EventType, err error)

XMLBase.NextTag iterates through the tokens until it reaches a StartTag or EndTag. It resolves urls in tag attributes relative to the current xml:base.

NextTag is similar to goxpp's NextTag method except it wont throw an error if the next immediate token isnt a Start/EndTag. Instead, it will continue to consume tokens until it hits a Start/EndTag or EndDocument.

func ParseDate

func ParseDate(ds string) (t time.Time, err error)

ParseDate parses a given date string using a large list of commonly found feed date formats.

func ParseExtension

func ParseExtension(fe ext.Extensions, p *xpp.Parser) (ext.Extensions, error)

ParseExtension parses the current element of the XMLPullParser as an extension element and updates the extension map

func ParseNameAddress

func ParseNameAddress(nameAddressText string) (name string, address string)

ParseNameAddress parses name/email strings commonly found in RSS feeds of the format "Example Name (example@site.com)" and other variations of this format.

func ParseText

func ParseText(p *xpp.Parser) (string, error)

ParseText is a helper function for parsing the text from the current element of the XMLPullParser. This function can handle parsing naked XML text from an element.

func ParseTextURL added in v1.4.0

func ParseTextURL(p *xpp.Parser) (string, error)

ParseTextURL is ParseText for an element whose text is a URL: it resolves the value against the element's xml:base when one is in scope. The base is captured before ParseText runs, because ParseText consumes the element's end tag, which pops the base off the stack.

func PrefixForNamespace added in v1.3.0

func PrefixForNamespace(space string, p *xpp.Parser) string

func ResolveHTML added in v1.2.1

func ResolveHTML(base *url.URL, relHTML string) (string, error)

Transforms html by resolving any relative URIs in attributes if an error occurs during parsing or serialization, then the original string is returned along with the error.

func ResolveURLIfBase added in v1.4.0

func ResolveURLIfBase(base *url.URL, s string) string

ResolveURLIfBase resolves s against base when an xml:base is in scope, returning s unchanged when base is nil or resolution fails. Element-content URLs (e.g. an RSS <link>) don't pass through resolveAttrs, so this lets them be resolved the same way attribute URLs already are. Resolving only when a base is present means URLs in feeds without xml:base are never round-tripped through url.Parse and so are never normalized.

func StripCDATA

func StripCDATA(str string) string

StripCDATA removes CDATA tags from the string content outside of CDATA tags is passed via DecodeEntities

func XmlBaseResolveUrl added in v1.3.0

func XmlBaseResolveUrl(b *url.URL, u string) (*url.URL, error)

resolve u relative to b

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL