moovweb / gokogiri

A light libxml wrapper for Go
MIT License
601 stars 95 forks source link

Sax #34

Open mattkanwisher opened 11 years ago

mattkanwisher commented 11 years ago

Do you guys have any plans for sax? We are starting to be needing it, might implement it. So was going to check if you had started it or had any ideas/concerns

mdayaram commented 11 years ago

Hmm, interesting. We currently don't have any plans to support SAX style parsing. If you're feeling ambitious, I'd say go for it! I believe libxml has some support for it.

jbowtie commented 11 years ago

It's not immediately obvious from the documentation, but you can do SAX processing using the standard 'encoding/xml" package.

You need to consume Decoder.Token until you get an io.EOF (or some other error); switch on the token type (xml.StartElement, xml.CharData, etc) and either do your handling or push something to a channel to represent an event.

xamgore commented 4 years ago

The standard encoding/xml package has very low performance, so the only way to parse huge XML files is SAX parsing: https://github.com/golang/go/issues/21823