https://github.com/mmcdole/goxpp
Go XML Pull Parser
https://github.com/mmcdole/goxpp
go golang pull-parser xml xml-parser
Last synced: 2 months ago
JSON representation
Go XML Pull Parser
- Host: GitHub
- URL: https://github.com/mmcdole/goxpp
- Owner: mmcdole
- License: mit
- Created: 2016-01-26T17:16:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-01-04T04:01:09.000Z (5 months ago)
- Last Synced: 2025-03-28T09:04:57.071Z (2 months ago)
- Topics: go, golang, pull-parser, xml, xml-parser
- Language: Go
- Homepage:
- Size: 50.8 KB
- Stars: 34
- Watchers: 3
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goxpp
[](https://github.com/mmcdole/goxpp/actions/workflows/ci.yml)
[](https://codecov.io/gh/mmcdole/goxpp)
[](http://doge.mit-license.org)
[](https://pkg.go.dev/github.com/mmcdole/goxpp)A lightweight XML Pull Parser for Go, inspired by [Java's XMLPullParser](http://www.xmlpull.org/v1/download/unpacked/doc/quick_intro.html). It provides fine-grained control over XML parsing with a simple, intuitive API.
## Features
- Pull-based parsing for fine-grained document control
- Efficient navigation and element skipping
- Simple, idiomatic Go API## Installation
```bash
go get github.com/mmcdole/goxpp
```## Quick Start
```go
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
}
}
```## Token Types
- `StartDocument`, `EndDocument`
- `StartTag`, `EndTag`
- `Text`, `Comment`
- `ProcessingInstruction`, `Directive`
- `IgnorableWhitespace`## Documentation
For detailed documentation and examples, visit [pkg.go.dev](https://pkg.go.dev/github.com/mmcdole/goxpp).
## License
This project is licensed under the [MIT License](LICENSE).