shared

package
v0.0.0-...-f53c0c8 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	TruncatedEntity         = errors.New("truncated entity")
	InvalidNumericReference = errors.New("invalid numeric reference")
)

Functions

func DecodeEntities

func DecodeEntities(str string) (string, error)

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

func IsExtension

func IsExtension(p *xpp.XMLPullParser) bool

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

func NewReaderLabel

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

func NewXMLSanitizerReader

func NewXMLSanitizerReader(xml io.Reader) io.Reader

NewXMLSanitizerReader creates an io.Reader that wraps another io.Reader and removes illegal xml characters from the io stream.

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.XMLPullParser) (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.XMLPullParser) (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 StripCDATA

func StripCDATA(str string) string

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

Types

type XMLBase

type XMLBase struct {
	URIAttrs map[string]bool
	// contains filtered or unexported fields
}

func (*XMLBase) CurrentBase

func (b *XMLBase) CurrentBase() string

func (*XMLBase) CurrentBaseURL

func (b *XMLBase) CurrentBaseURL() *url.URL

func (*XMLBase) FindRoot

func (b *XMLBase) FindRoot(p *xpp.XMLPullParser) (event xpp.XMLEventType, 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 (*XMLBase) NextTag

func (b *XMLBase) NextTag(p *xpp.XMLPullParser) (event xpp.XMLEventType, err error)

XMLBase.NextTag iterates through the tokens until it reaches a StartTag or EndTag It maintains the urlStack upon encountering StartTag and EndTags, so that the top of the stack (accessible through the CurrentBase() and CurrentBaseURL() methods) is the absolute base URI by which relative URIs should be resolved.

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 (*XMLBase) ResolveHTML

func (b *XMLBase) ResolveHTML(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 (*XMLBase) ResolveURL

func (b *XMLBase) ResolveURL(u string) (string, error)

resolve the given string as a URL relative to current base

Jump to

Keyboard shortcuts

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