mirror of
https://github.com/aclindsa/ofxgo.git
synced 2024-11-22 11:30:05 -05:00
Ignore whitespace character data xml Tokens
This commit is contained in:
parent
257495a343
commit
b90c3e0dcd
29
ofx.go
29
ofx.go
@ -239,8 +239,25 @@ func (or *Response) readSGMLHeaders(r *bufio.Reader) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (or *Response) readXMLHeaders(decoder *xml.Decoder) error {
|
func nextNonWhitespaceToken(decoder *xml.Decoder) (xml.Token, error) {
|
||||||
|
for {
|
||||||
tok, err := decoder.Token()
|
tok, err := decoder.Token()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if chars, ok := tok.(xml.CharData); ok {
|
||||||
|
strippedBytes := bytes.TrimSpace(chars)
|
||||||
|
if len(strippedBytes) != 0 {
|
||||||
|
return tok, nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return tok, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (or *Response) readXMLHeaders(decoder *xml.Decoder) error {
|
||||||
|
var tok xml.Token
|
||||||
|
tok, err := nextNonWhitespaceToken(decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if xmlElem, ok := tok.(xml.ProcInst); !ok || xmlElem.Target != "xml" {
|
} else if xmlElem, ok := tok.(xml.ProcInst); !ok || xmlElem.Target != "xml" {
|
||||||
@ -248,7 +265,7 @@ func (or *Response) readXMLHeaders(decoder *xml.Decoder) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse the OFX header
|
// parse the OFX header
|
||||||
tok, err = decoder.Token()
|
tok, err = nextNonWhitespaceToken(decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if ofxElem, ok := tok.(xml.ProcInst); ok && ofxElem.Target == "OFX" {
|
} else if ofxElem, ok := tok.(xml.ProcInst); ok && ofxElem.Target == "OFX" {
|
||||||
@ -330,7 +347,7 @@ func (or *Response) Unmarshal(reader io.Reader, xmlVersion bool) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tok, err := decoder.Token()
|
tok, err := nextNonWhitespaceToken(decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if ofxStart, ok := tok.(xml.StartElement); !ok || ofxStart.Name.Local != "OFX" {
|
} else if ofxStart, ok := tok.(xml.StartElement); !ok || ofxStart.Name.Local != "OFX" {
|
||||||
@ -338,7 +355,7 @@ func (or *Response) Unmarshal(reader io.Reader, xmlVersion bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal the signon message
|
// Unmarshal the signon message
|
||||||
tok, err = decoder.Token()
|
tok, err = nextNonWhitespaceToken(decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if signonStart, ok := tok.(xml.StartElement); ok && signonStart.Name.Local == "SIGNONMSGSRSV1" {
|
} else if signonStart, ok := tok.(xml.StartElement); ok && signonStart.Name.Local == "SIGNONMSGSRSV1" {
|
||||||
@ -349,7 +366,7 @@ func (or *Response) Unmarshal(reader io.Reader, xmlVersion bool) error {
|
|||||||
return errors.New("Missing opening SIGNONMSGSRSV1 xml element")
|
return errors.New("Missing opening SIGNONMSGSRSV1 xml element")
|
||||||
}
|
}
|
||||||
|
|
||||||
tok, err = decoder.Token()
|
tok, err = nextNonWhitespaceToken(decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if signonEnd, ok := tok.(xml.EndElement); !ok || signonEnd.Name.Local != "SIGNONMSGSRSV1" {
|
} else if signonEnd, ok := tok.(xml.EndElement); !ok || signonEnd.Name.Local != "SIGNONMSGSRSV1" {
|
||||||
@ -360,7 +377,7 @@ func (or *Response) Unmarshal(reader io.Reader, xmlVersion bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
tok, err = decoder.Token()
|
tok, err = nextNonWhitespaceToken(decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if ofxEnd, ok := tok.(xml.EndElement); ok && ofxEnd.Name.Local == "OFX" {
|
} else if ofxEnd, ok := tok.(xml.EndElement); ok && ofxEnd.Name.Local == "OFX" {
|
||||||
|
@ -63,7 +63,7 @@ type MessageSetList []MessageSet
|
|||||||
func (msl *MessageSetList) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
func (msl *MessageSetList) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
for {
|
for {
|
||||||
var msgset MessageSet
|
var msgset MessageSet
|
||||||
tok, err := d.Token()
|
tok, err := nextNonWhitespaceToken(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if end, ok := tok.(xml.EndElement); ok && end.Name.Local == start.Name.Local {
|
} else if end, ok := tok.(xml.EndElement); ok && end.Name.Local == start.Name.Local {
|
||||||
@ -71,7 +71,7 @@ func (msl *MessageSetList) UnmarshalXML(d *xml.Decoder, start xml.StartElement)
|
|||||||
return nil
|
return nil
|
||||||
} else if _, ok := tok.(xml.StartElement); ok {
|
} else if _, ok := tok.(xml.StartElement); ok {
|
||||||
// Found starting tag for <xxxMSGSET>. Get the next one (xxxMSGSETVn) and decode that struct
|
// Found starting tag for <xxxMSGSET>. Get the next one (xxxMSGSETVn) and decode that struct
|
||||||
tok, err := d.Token()
|
tok, err := nextNonWhitespaceToken(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if versionStart, ok := tok.(xml.StartElement); ok {
|
} else if versionStart, ok := tok.(xml.StartElement); ok {
|
||||||
@ -83,7 +83,7 @@ func (msl *MessageSetList) UnmarshalXML(d *xml.Decoder, start xml.StartElement)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Eat ending tags for <xxxMSGSET>
|
// Eat ending tags for <xxxMSGSET>
|
||||||
tok, err = d.Token()
|
tok, err = nextNonWhitespaceToken(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if _, ok := tok.(xml.EndElement); !ok {
|
} else if _, ok := tok.(xml.EndElement); !ok {
|
||||||
@ -129,7 +129,7 @@ func (pr ProfileResponse) Valid() (bool, error) {
|
|||||||
func DecodeProfileMessageSet(d *xml.Decoder, start xml.StartElement) ([]Message, error) {
|
func DecodeProfileMessageSet(d *xml.Decoder, start xml.StartElement) ([]Message, error) {
|
||||||
var msgs []Message
|
var msgs []Message
|
||||||
for {
|
for {
|
||||||
tok, err := d.Token()
|
tok, err := nextNonWhitespaceToken(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if end, ok := tok.(xml.EndElement); ok && end.Name.Local == start.Name.Local {
|
} else if end, ok := tok.(xml.EndElement); ok && end.Name.Local == start.Name.Local {
|
||||||
|
@ -146,7 +146,7 @@ func (air AcctInfoResponse) Valid() (bool, error) {
|
|||||||
func DecodeSignupMessageSet(d *xml.Decoder, start xml.StartElement) ([]Message, error) {
|
func DecodeSignupMessageSet(d *xml.Decoder, start xml.StartElement) ([]Message, error) {
|
||||||
var msgs []Message
|
var msgs []Message
|
||||||
for {
|
for {
|
||||||
tok, err := d.Token()
|
tok, err := nextNonWhitespaceToken(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if end, ok := tok.(xml.EndElement); ok && end.Name.Local == start.Name.Local {
|
} else if end, ok := tok.(xml.EndElement); ok && end.Name.Local == start.Name.Local {
|
||||||
|
Loading…
Reference in New Issue
Block a user