Skip to content

mmcdole/goxpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goxpp

Build Status codecov License Go Reference

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.

Features

  • Pull-based parsing for fine-grained document control
  • Efficient navigation and element skipping
  • Simple, idiomatic Go API

Installation

go get github.com/mmcdole/goxpp

Quick Start

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.

License

This project is licensed under the MIT License.

About

Go XML Pull Parser

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages