Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export token and add method SkipOne #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions xpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type XMLPullParser struct {
Text string

decoder *xml.Decoder
token interface{}
Token interface{}
}

func NewXMLPullParser(r io.Reader, strict bool, cr CharsetReader) *XMLPullParser {
Expand Down Expand Up @@ -109,16 +109,16 @@ func (p *XMLPullParser) NextToken() (event XMLEventType, err error) {
// XML decoder returns the EOF as an error
// but we want to return it as a valid
// EndDocument token instead
p.token = nil
p.Token = nil
p.Event = EndDocument
return p.Event, nil
}
return event, err
}

p.token = xml.CopyToken(token)
p.processToken(p.token)
p.Event = p.EventType(p.token)
p.Token = xml.CopyToken(token)
p.processToken(p.Token)
p.Event = p.EventType(p.Token)

return p.Event, nil
}
Expand Down Expand Up @@ -170,6 +170,18 @@ func (p *XMLPullParser) Skip() error {
}
}

func (p *XMLPullParser) SkipOne() error {
tok, err := p.NextToken()
if err != nil {
return err
}
if tok == EndTag {
return nil
} else {
return p.SkipOne()
}
}

func (p *XMLPullParser) Attribute(name string) string {
for _, attr := range p.Attrs {
if attr.Name.Local == name {
Expand Down Expand Up @@ -197,7 +209,7 @@ func (p *XMLPullParser) DecodeElement(v interface{}) error {

//tok := &p.token

startToken := p.token.(xml.StartElement)
startToken := p.Token.(xml.StartElement)

// Consumes all tokens until the matching end token.
err := p.decoder.DecodeElement(v, &startToken)
Expand All @@ -213,7 +225,7 @@ func (p *XMLPullParser) DecodeElement(v interface{}) error {
p.Event = EndTag
p.Depth--
p.Name = name
p.token = nil
p.Token = nil
return nil
}

Expand Down