Skip to content
A light libxml wrapper for Go
Go HTML C
Branch: master
Clone or download
Pull request Compare This branch is 1 commit behind merj:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
css
help
html
mem
util
xml
xpath
.gitignore
AUTHOR
LICENSE
Readme.md
VERSION
gokogiri.go
gokogiri_test.go

Readme.md

Gokogiri

LibXML bindings for the Go programming language.

By Zhigang Chen and Hampton Catlin

This is a major rewrite from v0 in the following places:

  • Separation of XML and HTML
  • Put more burden of memory allocation/deallocation on Go
  • Fragment parsing -- no more deep-copy
  • Serialization
  • Some API adjustment

Installation

# Linux
sudo apt-get install libxml2-dev
# Mac
brew install libxml2

go get github.com/merj/gokogiri

Running tests

go test github.com/merj/gokogiri/...

Basic example

package main

import (
  "net/http"
  "io/ioutil"
  "github.com/merj/gokogiri"
)

func main() {
  // fetch and read a web page
  resp, _ := http.Get("http://www.google.com")
  page, _ := ioutil.ReadAll(resp.Body)

  // parse the web page
  doc, _ := gokogiri.ParseHtml(page)

  // perform operations on the parsed page -- consult the tests for examples

  // important -- don't forget to free the resources when you're done!
  doc.Free()
}
You can’t perform that action at this time.