Documentation ¶
Index ¶
- type Attribute
- type AttributeIterator
- type Buffer
- type DOM
- type Document
- type Element
- func (e *Element) AddAttribute(key, value string)
- func (e *Element) Attribute(name string) (*Attribute, bool)
- func (e *Element) AttributeByIndex(i int) *Attribute
- func (e *Element) AttributesLen() int
- func (e *Element) HasAttribute(name string) bool
- func (e *Element) InnerHTML() string
- func (e *Element) MatchAttribute(name, value string) (*Attribute, bool)
- func (e *Element) SetInnerHTML(innerHTML string) error
- type ElementIterator
- type Pool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
type Attribute struct {
// contains filtered or unexported fields
}
Attribute represents HTML Element attribute
type AttributeIterator ¶
type AttributeIterator struct {
// contains filtered or unexported fields
}
AttributeIterator iterates over matching attributes
func (*AttributeIterator) Has ¶
func (at *AttributeIterator) Has() bool
Has returns true if there are more attributes matching given selectors
func (*AttributeIterator) Next ¶
func (at *AttributeIterator) Next() (*Attribute, error)
Next returns Attribute matching given selectors Note: it is needed to call Has before calling Next
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer hold the current DOM value
type DOM ¶
type DOM struct {
// contains filtered or unexported fields
}
DOM represents DOM structure
func New ¶
New parses template and creates new DOM. Filters can be specified to index some tags and attributes.
Example ¶
template := ` <!DOCTYPE html> <html lang="en"> <head> <title>Index</title> </head> <body> <p class="[class]">Classes</p> <img src="[src]" alt="alt"/> <div hidden="[hidden]">This is div inner</div> </body> </html>` dom, err := New(template) if err != nil { fmt.Println(err) return } filter := option.NewFilters( option.NewFilter("div", "hidden"), option.NewFilter("img", "src"), ) bufferSize := option.BufferSize(1024) document := dom.Document(filter, bufferSize) elemIt := document.Select("div", "hidden") for elemIt.Has() { elem, _ := elemIt.Next() fmt.Println(elem.InnerHTML()) _ = elem.SetInnerHTML("This will be new InnerHTML") attribute, ok := elem.MatchAttribute("hidden", "[hidden]") if ok { attribute.Set("true") fmt.Println(attribute.Value()) } } attributeIt := document.SelectAttributes("img", "src", "[src]") for attributeIt.Has() { attribute, _ := attributeIt.Next() attribute.Set("abcdef.jpg") fmt.Println(attribute.Value()) } fmt.Println(document.Render())
Output: This is div inner true abcdef.jpg <!DOCTYPE html> <html lang="en"> <head> <title>Index</title> </head> <body> <p class="[class]">Classes</p> <img src="abcdef.jpg" alt="alt"/> <div hidden="true">This will be new InnerHTML</div> </body> </html>
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document modifies the DOM
func (*Document) Select ¶
func (d *Document) Select(selectors ...string) *ElementIterator
Select returns ElementIterator to iterate over HTML Elements
func (*Document) SelectAttributes ¶
func (d *Document) SelectAttributes(selectors ...string) *AttributeIterator
SelectAttributes returns AttributeIterator to iterate over HTML Attributes
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents HTML Element
func (*Element) AddAttribute ¶
func (*Element) AttributeByIndex ¶
AttributeByIndex returns n-th Attribute
func (*Element) AttributesLen ¶
AttributesLen returns number of Element Attributes
func (*Element) HasAttribute ¶
func (*Element) MatchAttribute ¶
MatchAttribute returns an attribute that matches the supplied attribute name and value
func (*Element) SetInnerHTML ¶
SetInnerHTML updates InnerHTML of Element
type ElementIterator ¶
type ElementIterator struct {
// contains filtered or unexported fields
}
ElementIterator iterates over matching tags
func (*ElementIterator) Has ¶
func (it *ElementIterator) Has() bool
Has returns true if there are more tags matching given selectors
func (*ElementIterator) Next ¶
func (it *ElementIterator) Next() (*Element, error)
Next returns Element matching given selectors Note: it is needed to call Has before calling Next