Skip to content

Commit

Permalink
Fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamer Gur committed Jun 21, 2019
1 parent 1b306d7 commit cf60436
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,32 +398,37 @@ func (x *XMLParser) isComment() (bool, error) {

func (x *XMLParser) skipDeclerations() error {

var a, b []byte
var c, d byte
var err error
var a, c, d byte
var b []byte

scan_declartions:
for {
a, err = x.readByte()

// when identifying a xml declaration we need to know 2 bytes ahead. Unread works 1 byte at a time so we use Peek and read together.
a, err = x.reader.Peek(1)

if err != nil {
return err
}

if x.isWS(a) {
continue
}
if a[0] == '<' {

if a == '<' {
// read peaked byte first
_, err = x.readByte()
if err != nil {
return err
}

b, err = x.reader.Peek(1) // this is needed because we cant unread 2 bytes consequtively
b, err = x.reader.Peek(1)

if err != nil {
return err
}

if b[0] == '!' || b[0] == '?' { // either comment or decleration

// read peaked byte
_, err = x.readByte()

if err != nil {
Expand All @@ -450,12 +455,19 @@ scan_declartions:

} else { // declerations ends.

err = x.unreadByte()
return err
return nil

}

}

// read peaked byte
_, err = x.readByte()

if err != nil {
return err
}

}

skipComment:
Expand Down

0 comments on commit cf60436

Please sign in to comment.