encoding/xml expose line

147 views
Skip to first unread message

Patrick

unread,
Apr 16, 2021, 10:44:19 AM4/16/21
to golang-nuts
Hello all,

I use the XML package from the standard library (encoding/xml) and I wonder why the line attribute of the decoder is not exposed such as 

func (d *Decoder) InputLine() int {
    return d.line
}

The offset for example is exposed:

func (d *Decoder) InputOffset() int64 {
   return d.offset
}

Is there an obvious reason for that that I am missing? Or more in the line of "not yet implemented"?

Thanks 

  Patrick



clba...@gmail.com

unread,
Apr 17, 2021, 11:39:59 AM4/17/21
to golang-nuts
Don't know what you're trying to do, but the only time I've wanted the line number during decoding is when an error occurs.  Then I retrieve it using xml.SyntaxError, assuming that 'error' is of type *xml.SyntaxError.

Patrick

unread,
Apr 17, 2021, 12:45:11 PM4/17/21
to golang-nuts
I have my own programming language (a bit similar to XSLT) and the XML can be valid but there still might be an error such as an uninitialised variable. I'd like to present feedback to the user on which line the error occurred.

I am thinking about opening an issue on GitHub and providing a (simple) patch.

Patrick

peterGo

unread,
Apr 17, 2021, 4:09:57 PM4/17/21
to golang-nuts


Patrick,

A similar proposal has just been accepted for encoding/csv:

encoding/csv: add the ability to get the line number of a record #44221

Peter

Patrick

unread,
Apr 19, 2021, 5:21:51 AM4/19/21
to golang-nuts
Thank you Peter, 

I have opened an issue (https://github.com/golang/go/issues/45628). 

Patrick

Reply all
Reply to author
Forward
0 new messages