Skip to content

Instantly share code, notes, and snippets.

@orisano
Created June 26, 2024 17:19
Show Gist options
  • Select an option

  • Save orisano/6f819402698ae0488d08db01763b3e75 to your computer and use it in GitHub Desktop.

Select an option

Save orisano/6f819402698ae0488d08db01763b3e75 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
xmlparser "github.com/tamerh/xml-stream-parser"
)
func main() {
f, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer f.Close()
br := bufio.NewReaderSize(f, 2*1024*1024)
r := xmlparser.NewXMLParser(br, "location")
count := 0
for xml := range r.Stream() {
if strings.Contains(xml.InnerText, "Africa") {
count++
}
}
fmt.Println("counter =", count)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment