parser

package
v0.0.0-...-ca70e36 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HTMLParseRecover enables relaxed parsing
	HTMLParseRecover HTMLOption = 1 << 0
	// HTMLParseNoDefDTD disables using a default doctype when absent
	HTMLParseNoDefDTD = 1 << 2
	// HTMLParseNoError suppresses error reports
	HTMLParseNoError = 1 << 5
	// HTMLParseNoWarning suppresses warning reports
	HTMLParseNoWarning = 1 << 6
	// HTMLParsePedantic enables pedantic error reporting
	HTMLParsePedantic = 1 << 7
	// HTMLParseNoBlanks removes blank nodes
	HTMLParseNoBlanks = 1 << 8
	// HTMLParseNoNet forbids network access during parsing
	HTMLParseNoNet = 1 << 11
	// HTMLParseNoImplied disables implied html/body elements
	HTMLParseNoImplied = 1 << 13
	// HTMLParseCompact enables compaction of small text nodes
	HTMLParseCompact = 1 << 16
	// HTMLParseIgnoreEnc ignores internal document encoding hints
	HTMLParseIgnoreEnc = 1 << 21
)

DefaultHTMLOptions represents the default set of options used in the ParseHTML* functions

Variables

View Source
var (
	// ErrMalformedXML is returned when the XML source is malformed
	ErrMalformedXML = errors.New("malformed XML")
)

Functions

This section is empty.

Types

type Ctxt

type Ctxt struct {
	// contains filtered or unexported fields
}

Ctxt represents the Parser context. You normally should be using Parser, but if you for some reason need to do more low-level magic you will have to tinker with this struct

func NewCtxt

func NewCtxt(s string, o Option) (*Ctxt, error)

NewCtxt creates a new Parser context

func (*Ctxt) Free

func (ctx *Ctxt) Free() error

Free releases the underlying C struct

func (Ctxt) Parse

func (ctx Ctxt) Parse() error

Parse starts the parsing on the Ctxt

func (Ctxt) Pointer

func (ctx Ctxt) Pointer() uintptr

Pointer returns the underlying C struct

type HTMLOption

type HTMLOption int

HTMLOption represents the HTML parser options that can be used when parsing HTML

type Option

type Option int

Option represents the parser option bit

const (
	XMLParseRecover    Option = 1 << iota /* recover on errors */
	XMLParseNoEnt                         /* substitute entities */
	XMLParseDTDLoad                       /* load the external subset */
	XMLParseDTDAttr                       /* default DTD attributes */
	XMLParseDTDValid                      /* validate with the DTD */
	XMLParseNoError                       /* suppress error reports */
	XMLParseNoWarning                     /* suppress warning reports */
	XMLParsePedantic                      /* pedantic error reporting */
	XMLParseNoBlanks                      /* remove blank nodes */
	XMLParseSAX1                          /* use the SAX1 interface internally */
	XMLParseXInclude                      /* Implement XInclude substitition  */
	XMLParseNoNet                         /* Forbid network access */
	XMLParseNoDict                        /* Do not reuse the context dictionnary */
	XMLParseNsclean                       /* remove redundant namespaces declarations */
	XMLParseNoCDATA                       /* merge CDATA as text nodes */
	XMLParseNoXIncNode                    /* do not generate XINCLUDE START/END nodes */
	XMLParseCompact                       /* compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree) */
	XMLParseOld10                         /* parse using XML-1.0 before update 5 */
	XMLParseNoBaseFix                     /* do not fixup XINCLUDE xml:base uris */
	XMLParseHuge                          /* relax any hardcoded limit from the parser */
	XMLParseOldSAX                        /* parse using SAX2 interface before 2.7.0 */
	XMLParseIgnoreEnc                     /* ignore internal document encoding hint */
	XMLParseBigLines                      /* Store big lines numbers in text PSVI field */
	XMLParseMax
	XMLParseEmptyOption Option = 0
)

func (*Option) Set

func (o *Option) Set(options ...Option)

Set flips the option bit in the given Option

func (Option) String

func (o Option) String() string

String creates a string representation of the Option

type Parser

type Parser struct {
	Options Option
}

Parser represents the high-level parser.

func New

func New(opts ...Option) *Parser

New creates a new Parser with the given options.

func (*Parser) Parse

func (p *Parser) Parse(buf []byte) (types.Document, error)

Parse parses XML from the given byte buffer

func (*Parser) ParseReader

func (p *Parser) ParseReader(in io.Reader) (types.Document, error)

ParseReader parses XML from the given io.Reader

func (*Parser) ParseString

func (p *Parser) ParseString(s string) (types.Document, error)

ParseString parses XML from the given string

Jump to

Keyboard shortcuts

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