Skip to content

sax-jsvshtmlquery

BlueOak-1.0.0 96 1 1,153
288.7 million (month) Feb 09 2011 1.6.0(2026-03-17 01:32:31 ago)
781 1 8 MIT
Feb 07 2019 58.1 thousand (month) v1.3.6(2026-03-06 04:46:15 ago)

sax-js is a streaming XML parser for Node.js that is built on top of the sax C library. It is designed to be fast, low-memory, and easy to use. It is commonly used for parsing large XML files, as it allows you to process the XML data incrementally, rather than loading the entire file into memory at once.

sax-js is a low-level html tree parser and does not provide html query capabilities (like CSS selectors) though it can be useful in HTML tree parsing and serialization.

htmlquery is a Go library that allows you to parse and extract data from HTML documents using XPath expressions. It provides a simple and intuitive API for traversing and querying the HTML tree structure, and it is built on top of the popular Goquery library.

Example Use


```javascript const fs = require("fs"); const sax = require("sax"); const xmlStream = fs.createReadStream("example.xml"); const saxParser = sax.createStream(true, {}); saxParser.on("opentag", function(node) { console.log(`<${node.name}>`); }); saxParser.on("closetag", function(nodeName) { console.log(`</${nodeName}>`); }); saxParser.on("text", function(text) { console.log(text); }); xmlStream.pipe(saxParser); ```
```go package main import ( "fmt" "log" "github.com/antchfx/htmlquery" ) func main() { // Parse the HTML string doc, err := htmlquery.Parse([]byte(`

Hello, World!

  • Item 1
  • Item 2
  • Item 3
`)) if err != nil { log.Fatal(err) } // Extract the text of the first

element h1 := htmlquery.FindOne(doc, "//h1") fmt.Println(htmlquery.InnerText(h1)) // "Hello, World!" // Extract the text of all
  • elements lis := htmlquery.Find(doc, "//li") for _, li := range lis { fmt.Println(htmlquery.InnerText(li)) } // "Item 1" // "Item 2" // "Item 3" } ```
  • Alternatives / Similar


    Was this page helpful?