A lightweight XML Pull Parser for Go, inspired by Java's XMLPullParser. It provides fine-grained control over XML parsing with a simple, intuitive API.
- Pull-based parsing for fine-grained document control
- Efficient navigation and element skipping
- Simple, idiomatic Go API
go get github.com/mmcdole/goxpp
import "github.com/mmcdole/goxpp"
// Parse RSS feed
file, _ := os.Open("feed.rss")
p := xpp.NewXMLPullParser(file, false, nil)
// Find channel element
for tok, err := p.NextTag(); tok != xpp.EndDocument; tok, err = p.NextTag() {
if err != nil {
return err
}
if tok == xpp.StartTag && p.Name == "channel" {
// Process channel contents
for tok, err = p.NextTag(); tok != xpp.EndTag; tok, err = p.NextTag() {
if err != nil {
return err
}
if tok == xpp.StartTag {
switch p.Name {
case "title":
title, _ := p.NextText()
fmt.Printf("Feed: %s\n", title)
case "item":
// Get item title and skip rest
p.NextTag()
title, _ := p.NextText()
fmt.Printf("Item: %s\n", title)
p.Skip()
default:
p.Skip()
}
}
}
break
}
}
StartDocument
,EndDocument
StartTag
,EndTag
Text
,Comment
ProcessingInstruction
,Directive
IgnorableWhitespace
For detailed documentation and examples, visit pkg.go.dev.
This project is licensed under the MIT License.