Documentation ¶
Index ¶
- Constants
- Variables
- type Attributes
- type Element
- func (e *Element) Append(elem *Element)
- func (e *Element) Attribute(key string) string
- func (e *Element) Find(tagName string, attrs ...string) *Element
- func (e *Element) FindAll(tagName string, attrs ...string) []*Element
- func (e *Element) FindAllWithAttrs(tagName string, attrs Attributes) []*Element
- func (e *Element) FindWithAttrs(tagName string, attrs Attributes) *Element
- func (e *Element) SetAttribute(key, value string)
- func (e *Element) String() string
- func (e *Element) Text() string
- type ElementType
- type Stack
Constants ¶
const LineSeparator = "\n"
LineSeparator is the carrage return.
Variables ¶
var ErrInvalidPair = errors.New("open/close tag mismatched")
ErrInvalidPair is error returned by failures to parse an HTML.
Functions ¶
This section is empty.
Types ¶
type Attributes ¶
An Attributes stores key/value attribute pairs in the tag.
func MakeAttrs ¶
func MakeAttrs(s ...string) (attrs Attributes)
MakeAttrs returns Attribute consisting of pairs. this function needs the even number of strings to make key/value pairs. so, if length of string slice is odd number, the last is dropped.
type Element ¶
type Element struct { Type ElementType Content string Attrs Attributes Children []*Element // contains filtered or unexported fields }
An Element consists of ElementType and Content
func (*Element) Attribute ¶
Attribute returns the value matching with the key. if the Attrs doesn't have the key, empty string is returned.
func (*Element) Find ¶
Find returns an element containing attrs with the same tag throughout its subelements. if no element is found, this function returns nil. attrs is mapped to Attributes by calling MakeAttrs
func (*Element) FindAll ¶
FindAll returns all elements containing attrs with the same tag in the subelements. attrs is mapped to Attributes by calling MakeAttrs
func (*Element) FindAllWithAttrs ¶
func (e *Element) FindAllWithAttrs(tagName string, attrs Attributes) []*Element
FindAllWithAttrs returns all elements containing attrs with the same tag in the subelements.
func (*Element) FindWithAttrs ¶
func (e *Element) FindWithAttrs(tagName string, attrs Attributes) *Element
FindWithAttrs returns an element containing attrs with the same tag in the subelements. if no such element exists, returns nil.
func (*Element) SetAttribute ¶
SetAttribute puts the given key-value pair into the attribute map in this element.
type ElementType ¶
type ElementType uint32
An ElementType is the type of Element.
const ( DocumentType ElementType = iota TagType TextType )
These are types for Element